git » nmdb » commit cdc1ab2

Allow the ruby default value to be parametrized and changed.

author Alberto Bertogli
2007-06-29 13:26:18 UTC
committer Alberto Bertogli
2007-06-29 13:26:18 UTC
parent f54d724a47ee6673fee016913eee3261988665e9

Allow the ruby default value to be parametrized and changed.

This mimics the behaviour of the default hash object.

It also fixes the automarshal attribute, which should have been
attr_accessor (r/w) instead of attr_writer (write only).

Signed-off-by: Alberto Bertogli <albertito@gmail.com>

bindings/ruby/nmdb.rb +5 -3

diff --git a/bindings/ruby/nmdb.rb b/bindings/ruby/nmdb.rb
index 608a55f..a47c0a0 100644
--- a/bindings/ruby/nmdb.rb
+++ b/bindings/ruby/nmdb.rb
@@ -9,11 +9,13 @@ end
 
 
 class GenericDB
-	attr_writer :automarshal
+	attr_accessor :automarshal
+	attr_accessor :default
 
-	def initialize()
+	def initialize(default = nil)
 		@db = Nmdb_ll::DB.new
 		@automarshal = true
+		@default = default
 	end
 
 	def add_tipc_server(port = -1)
@@ -66,7 +68,7 @@ class GenericDB
 			return r
 		elsif r == -1 then
 			# key not in the database
-			return nil
+			return @default
 		elsif r <= 2 then
 			raise NetworkException
 		else