Class: OptionHelpers::OptionMatcher
- Inherits:
-
Object
- Object
- OptionHelpers::OptionMatcher
- Defined in:
- lib/option.rb
Instance Attribute Summary collapse
-
#return_value ⇒ Object
readonly
Returns the value of attribute return_value.
Instance Method Summary collapse
- #case(type) ⇒ Object
- #else ⇒ Object
-
#initialize(option) ⇒ OptionMatcher
constructor
A new instance of OptionMatcher.
Constructor Details
#initialize(option) ⇒ OptionMatcher
Returns a new instance of OptionMatcher.
5 6 7 8 |
# File 'lib/option.rb', line 5 def initialize(option) @option = option @return_value = nil end |
Instance Attribute Details
#return_value ⇒ Object (readonly)
Returns the value of attribute return_value.
3 4 5 |
# File 'lib/option.rb', line 3 def return_value @return_value end |
Instance Method Details
#case(type) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/option.rb', line 10 def case(type) if type.is_a?(OptionType) if @option.present? option_val = @option.get if option_val.is_a?(type.type) @return_value = yield(option_val) end end elsif type == SomeClass if @option.present? @return_value = yield(@option.get) end elsif type.is_a?(NoneClass) if !@option.present? @return_value = yield(@option) end else raise TypeError, "can't match an Option against a #{type.to_s}" end end |
#else ⇒ Object
31 32 33 |
# File 'lib/option.rb', line 31 def else @return_value = yield(@option) end |