Module: Fear::OptionApi

Included in:
Fear
Defined in:
lib/fear/option_api.rb

Instance Method Summary collapse

Instance Method Details

#noneFear::None

Examples:

Fear.none #=> #<Fear::None>

Returns:



28
29
30
# File 'lib/fear/option_api.rb', line 28

def none
  Fear::None
end

#option(value) ⇒ Fear::Some, Fear::None

An Option factory which creates Some if the argument is not nil, and None if it is nil.

Examples:

Fear.option(nil) #=> #<Fear::None>
Fear.option(17) #=> #<Fear::Some get=17>

Parameters:

  • value (any)

Returns:



16
17
18
19
20
21
22
# File 'lib/fear/option_api.rb', line 16

def option(value)
  if value.nil?
    none
  else
    some(value)
  end
end

#some(value) ⇒ Fear::Some

Examples:

Fear.some(17) #=> #<Fear::Some get=17>
Fear.some(nil) #=> #<Fear::Some get=nil>

Parameters:

  • value (any)

Returns:



38
39
40
# File 'lib/fear/option_api.rb', line 38

def some(value)
  Fear::Some.new(value)
end