Class: DeepStruct::HashWrapper
- Inherits:
-
DeepWrapper
- Object
- DeepWrapper
- DeepStruct::HashWrapper
show all
- Defined in:
- lib/hem/patches/deepstruct.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/hem/patches/deepstruct.rb', line 5
def method_missing(method, *args, &block)
return @value.send(method, *args, &block) if @value.respond_to?(method)
method = method.to_s
if method.chomp!('?')
key = method.to_sym
self.has_key?(key) && !!self[key]
elsif method.chomp!('=')
raise ArgumentError, "wrong number of arguments (#{arg_count} for 1)", caller(1) if args.length != 1
self[method] = args[0]
elsif args.length == 0 && self.has_key?(method)
self[method]
else
Hem::Null.new
end
end
|
Instance Method Details
#to_hash_sym ⇒ Object
21
22
23
|
# File 'lib/hem/patches/deepstruct.rb', line 21
def to_hash_sym
unwrap.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
end
|