Class: OptionHelpers::OptionMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valueObject (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

#elseObject



31
32
33
# File 'lib/option.rb', line 31

def else
  @return_value = yield(@option)
end