Module: Garcon::Extensions::MethodWriter
- Defined in:
- lib/garcon/core_ext/method_access.rb
Overview
Note:
That MethodWriter also overrides #respond_to such that any #method_name= will respond appropriately as true.
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.
Instance Method Summary collapse
- #convert_key(key) ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #respond_to?(name, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/garcon/core_ext/method_access.rb', line 86 def method_missing(name, *args) if args.size == 1 && name.to_s =~ /(.*)=$/ return self[convert_key(Regexp.last_match[1])] = args.first end super end |
Instance Method Details
#convert_key(key) ⇒ Object
94 95 96 |
# File 'lib/garcon/core_ext/method_access.rb', line 94 def convert_key(key) key.to_s end |
#respond_to?(name, include_private = false) ⇒ Boolean
81 82 83 84 |
# File 'lib/garcon/core_ext/method_access.rb', line 81 def respond_to?(name, include_private = false) return true if name.to_s =~ /=$/ super end |