Module: Fear::Option::Mixin

Included in:
Mixin
Defined in:
lib/fear/option.rb

Overview

Include this mixin to access convenient factory methods.

Examples:

include Fear::Option::Mixin

Option(17)  #=> #<Fear::Some value=17>
Option(nil) #=> #<Fear::None>
Some(17)    #=> #<Fear::Some value=17>
None        #=> #<Fear::None>

Constant Summary collapse

None =
Fear::None

Instance Method Summary collapse

Instance Method Details

#NoneNone

Returns:



219
220
221
# File 'lib/fear/option.rb', line 219

def None
  Fear::None
end

#Option(value) ⇒ Some, None

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

Examples:

Option(v)

Parameters:

  • value (any)

Returns:



210
211
212
213
214
215
216
# File 'lib/fear/option.rb', line 210

def Option(value)
  if value.nil?
    None
  else
    Some(value)
  end
end

#Some(value) ⇒ None

Parameters:

  • value (any)

    except nil

Returns:



225
226
227
# File 'lib/fear/option.rb', line 225

def Some(value)
  Some.new(value)
end