Class: HashWithQuickAccess
- Inherits:
-
Object
- Object
- HashWithQuickAccess
show all
- Defined in:
- lib/hash_with_quick_access.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of HashWithQuickAccess.
2
3
4
|
# File 'lib/hash_with_quick_access.rb', line 2
def initialize(hash)
@hash = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/hash_with_quick_access.rb', line 6
def method_missing(key, *args, &block)
if key?(key)
fetch_possibly_decorated_value(key)
elsif hash.respond_to?(key)
delegate_and_decorate(key, *args, &block)
else
fail KeyError, "key :#{key} was not found"
end
end
|
Instance Method Details
#[](key) ⇒ Object
24
25
26
|
# File 'lib/hash_with_quick_access.rb', line 24
def [](key)
send(key)
end
|
#keys ⇒ Object
20
21
22
|
# File 'lib/hash_with_quick_access.rb', line 20
def keys
hash.keys.map(&:to_sym)
end
|
#respond_to?(method_name, include_private = false) ⇒ Boolean
16
17
18
|
# File 'lib/hash_with_quick_access.rb', line 16
def respond_to?(method_name, include_private = false)
key?(method_name) || super
end
|