Class: OpenHash
Defined Under Namespace
Modules: VERSION
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ OpenHash
constructor
A new instance of OpenHash.
- #method_missing(method_name, *args, &block) ⇒ Object
- #methods ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(hash = {}) ⇒ OpenHash
Returns a new instance of OpenHash.
5 6 7 8 9 |
# File 'lib/open_hash.rb', line 5 def initialize(hash = {}) hash.each do |key, value| self[key] = value end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/open_hash.rb', line 11 def method_missing(method_name, *args, &block) if method_name.to_s.end_with?("?") has_key?(method_name.to_s.chomp("?").to_sym) || has_key?(method_name.to_s.chomp("?")) elsif has_key?(method_name) self[method_name] elsif has_key?(method_name.to_s) self[method_name.to_s] elsif method_name.to_s.end_with?("=") self[method_name.to_s.chomp("=").to_sym] = args.first else super end end |
Instance Method Details
#methods ⇒ Object
25 26 27 |
# File 'lib/open_hash.rb', line 25 def methods super + setter_methods + getter_methods + predicate_methods end |