Class: Smartgen::ObjectHash
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- Smartgen::ObjectHash
show all
- Defined in:
- lib/smartgen/object_hash.rb
Overview
A hash that has method accessors for each key.
For example:
hash = ObjectHash.new({:foo => 'bar'})
puts hash.foo
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/smartgen/object_hash.rb', line 24
def method_missing(name, *args)
if has_key?(name)
self[name]
elsif setter?(name)
self[name.to_s.chop] = args.first
else
$stderr.puts "warning: key #{name} not found on #{inspect}"
Smartgen::ObjectHash.new
end
end
|
Instance Method Details
#dup ⇒ Object
11
12
13
|
# File 'lib/smartgen/object_hash.rb', line 11
def dup
Smartgen::ObjectHash.new(self)
end
|
#inspect ⇒ Object
19
20
21
|
# File 'lib/smartgen/object_hash.rb', line 19
def inspect
"ObjectHash(#{super})"
end
|
#respond_to?(method) ⇒ Boolean
15
16
17
|
# File 'lib/smartgen/object_hash.rb', line 15
def respond_to?(method)
has_key?(method) || (setter?(method) && has_key?(method.to_s.chop)) || super
end
|