Class: Adyen::HashWithAccessors
- Inherits:
-
Hash
- Object
- Hash
- Adyen::HashWithAccessors
show all
- Defined in:
- lib/adyen/hash_with_accessors.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/adyen/hash_with_accessors.rb', line 12
def method_missing(method, *args)
string_key = method.to_s.sub(/=\z/, '')
sym_key = string_key.to_sym
key = if key?(string_key)
string_key
elsif key?(sym_key)
sym_key
end
return super unless key
assignment = sym_key != method
if assignment
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1)" unless args.size == 1
self[key] = args.first
else
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)" unless args.empty?
self[key]
end
end
|
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
37
38
39
40
|
# File 'lib/adyen/hash_with_accessors.rb', line 37
def respond_to_missing?(method, include_private = false)
string_key = method.to_s.sub(/=\z/, '')
key?(string_key) || key?(string_key.to_sym) || super
end
|