Module: XMP::Convenience
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
26
27
28
29
30
|
# File 'lib/xmp/convenience.rb', line 26
def method_missing(method_name, *arguments, &block)
return super unless include? method_name
raise ArgumentError, "wrong number of arguments (given #{arguments.size}, expected 0)" if arguments.any?
self[method_name]
end
|
Instance Method Details
#[](key) ⇒ Object
6
7
8
9
10
|
# File 'lib/xmp/convenience.rb', line 6
def [](key)
return unless key = key_map[key]
@entries ||= {}
@entries[key] ||= get(key)
end
|
#include?(key) ⇒ Boolean
2
3
4
|
# File 'lib/xmp/convenience.rb', line 2
def include?(key)
key_map.include? key
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
12
13
14
|
# File 'lib/xmp/convenience.rb', line 12
def respond_to_missing?(method_name, include_private = false)
include?(method_name) or super
end
|
#to_h ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/xmp/convenience.rb', line 16
def to_h
list.map do |key|
result = self[key]
result = result.to_h if result.is_a? XMP::Convenience
[key, result]
end.to_h
end
|