Module: Hashie::Extensions::MethodWriter
- Defined in:
- lib/hashie/extensions/method_access.rb
Overview
MethodWriter gives you #key_name= shortcuts for writing to your hash. Keys are written as strings, override #convert_key if you would like to have symbols or something else.
Note that MethodWriter also overrides #respond_to such that any #method_name= will respond appropriately as true.
Instance Method Summary (collapse)
- - (Object) convert_key(key)
- - (Object) method_missing(name, *args)
- - (Boolean) respond_to?(name, include_private = false)
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(name, *args)
65 66 67 68 69 70 71 |
# File 'lib/hashie/extensions/method_access.rb', line 65 def method_missing(name, *args) if args.size == 1 && name.to_s =~ /(.*)=$/ return self[convert_key($1)] = args.first end super end |
Instance Method Details
- (Object) convert_key(key)
73 74 75 |
# File 'lib/hashie/extensions/method_access.rb', line 73 def convert_key(key) key.to_s end |
- (Boolean) respond_to?(name, include_private = false)
60 61 62 63 |
# File 'lib/hashie/extensions/method_access.rb', line 60 def respond_to?(name, include_private = false) return true if name.to_s =~ /=$/ super end |