Class: Gtk2AppLib::KeyValues
- Inherits:
-
Hash
- Object
- Hash
- Gtk2AppLib::KeyValues
- Defined in:
- lib/gtk2applib/keyvalues.rb
Overview
KeyValues is a Hash. if
key_values = Gtk2AppLib::KeyValues.new( hash1, hash2, hash3, ... )
then key_values will have all the keys in hash1 set to the values in hash1, and then add the (key,values) in hash2 it may be missing, and so on... That means that hash1 has priority over hash2 in setting keys, and so on.. As actually used, it works like this:
key_values =
Gtk2AppLib::KeyValue.new(user_inputs, method_defaults, class_defaults)
key_values remains a simple "flat" hash (when built from "flat" hashes).
Instance Method Summary (collapse)
-
- (Object) dup(*hashes)
Creates a new KeyValues hash, with self as a supplement.
-
- (KeyValues) initialize(*hashes)
constructor
key_values =.
-
- (Object) modify(hash)
This method is added for completeness (not actually used by Gtk2AppLib).
-
- (Object) supplement(hash)
This is the (key,values) appending method used by the constructor.
Constructor Details
- (KeyValues) initialize(*hashes)
key_values =
Gtk2AppLib::KeyValue.new(user_inputs, method_defaults, class_defaults)
34 35 36 37 38 39 40 |
# File 'lib/gtk2applib/keyvalues.rb', line 34 def initialize(*hashes) super(nil) while hsh = hashes.shift do raise "Expected Hash Values" unless hsh.kind_of?(Hash) supplement(hsh) end end |
Instance Method Details
- (Object) dup(*hashes)
Creates a new KeyValues hash, with self as a supplement. So still called "dup"? Behaves like dup if no hashes are given.
47 48 49 50 |
# File 'lib/gtk2applib/keyvalues.rb', line 47 def dup(*hashes) hashes.push(self) KeyValues.new(*hashes) end |
- (Object) modify(hash)
This method is added for completeness (not actually used by Gtk2AppLib). The given hash will overwrite.
17 18 19 20 |
# File 'lib/gtk2applib/keyvalues.rb', line 17 def modify(hash) hash.each { |key, value| self[key] = value } self end |
- (Object) supplement(hash)
This is the (key,values) appending method used by the constructor.
25 26 27 28 |
# File 'lib/gtk2applib/keyvalues.rb', line 25 def supplement(hash) hash.each { |key, value| self[key] = value if !self.has_key?(key) } self end |