Class: Ruco::OptionAccessor
Overview
Can be used like a hash, but also allows .key access
Instance Attribute Summary collapse
-
#wrapped ⇒ Object
readonly
Returns the value of attribute wrapped.
Instance Method Summary collapse
-
#initialize(wrapped = {}) ⇒ OptionAccessor
constructor
A new instance of OptionAccessor.
- #method_missing(method, *args) ⇒ Object
- #nested(key) ⇒ Object
Constructor Details
#initialize(wrapped = {}) ⇒ OptionAccessor
Returns a new instance of OptionAccessor.
7 8 9 |
# File 'lib/ruco/option_accessor.rb', line 7 def initialize(wrapped={}) @wrapped = wrapped end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
19 20 21 22 23 |
# File 'lib/ruco/option_accessor.rb', line 19 def method_missing(method, *args) base = method.to_s.sub('=','').to_sym raise if args.size != 1 @wrapped[base] = args.first end |
Instance Attribute Details
#wrapped ⇒ Object (readonly)
Returns the value of attribute wrapped.
4 5 6 |
# File 'lib/ruco/option_accessor.rb', line 4 def wrapped @wrapped end |