Class: OptionPicker::Options
- Inherits:
-
Object
- Object
- OptionPicker::Options
- Defined in:
- lib/option_picker.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(default_value, options = {}) ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize(default_value, options = {}) ⇒ Options
Returns a new instance of Options.
7 8 9 10 11 12 13 |
# File 'lib/option_picker.rb', line 7 def initialize(default_value, ={}) = .is_a?(Array) ? Hash[.map {|o| [o,o] }] : @options = .each_with_object(Hash.new(default_value)) do |(key, value), memo| memo[key.to_sym] = value end end |
Instance Method Details
#[](index) ⇒ Object
15 16 17 18 |
# File 'lib/option_picker.rb', line 15 def [](index) index = index.to_sym if index.respond_to?(:to_sym) @options[index] end |