Class: Destruct::Hash
- Inherits:
-
Hash
- Object
- Hash
- Destruct::Hash
show all
- Defined in:
- lib/destruct/hash.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
24
25
26
|
# File 'lib/destruct/hash.rb', line 24
def method_missing(method, *)
key?(method) ? self[method] : super
end
|
Instance Method Details
3
4
5
6
7
|
# File 'lib/destruct/hash.rb', line 3
def [](key)
super(key) || super(key.to_s) || to_ary[key]
rescue TypeError
nil
end
|
#[]=(key, value) ⇒ Object
9
10
11
12
|
# File 'lib/destruct/hash.rb', line 9
def []=(key, value)
to_ary << value
super
end
|
#key?(key) ⇒ Boolean
14
15
16
|
# File 'lib/destruct/hash.rb', line 14
def key?(key)
super(key) || super(key.to_s)
end
|
18
19
20
|
# File 'lib/destruct/hash.rb', line 18
def to_ary
@to_ary ||= values
end
|