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:



26
27
28
# File 'lib/fear/option_api.rb', line 26

def none
  Fear::None
end

#option(value) ⇒ Fear::Option<any>

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:



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

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 (Object)

Returns:



36
37
38
# File 'lib/fear/option_api.rb', line 36

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