Class: DeepStruct::HashWrapper
- Inherits:
-
DeepWrapper
- Object
- DeepWrapper
- DeepStruct::HashWrapper
- Defined in:
- lib/hobo/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/hobo/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 Hobo::Null.new end end |