Class: RFunc::AbstractOption
- Inherits:
-
Object
- Object
- RFunc::AbstractOption
- Defined in:
- lib/rfunc/option.rb
Instance Method Summary collapse
-
#==(object) ⇒ Boolean
Comparator that allows one Option to be compared against another by value.
-
#filter(&block) ⇒ RFunc::Option
(also: #find)
Filters the Some by a given function.
-
#filter_not(&block) ⇒ RFunc::Option
Filters the Some by the inverse of a given function.
-
#get ⇒ Any
Extracts the value of the option.
-
#initialize(value) ⇒ AbstractOption
constructor
Initializes the class.
-
#is_option?(el) ⇒ Boolean
Tests whether or not an object is an Option.
Constructor Details
#initialize(value) ⇒ AbstractOption
Initializes the class
11 12 13 |
# File 'lib/rfunc/option.rb', line 11 def initialize(value) @value = value end |
Instance Method Details
#==(object) ⇒ Boolean
Comparator that allows one Option to be compared against another by value
21 22 23 |
# File 'lib/rfunc/option.rb', line 21 def ==(object) object.class == self.class && object.get == @value end |
#filter(&block) ⇒ RFunc::Option Also known as: find
Filters the Some by a given function
38 39 40 |
# File 'lib/rfunc/option.rb', line 38 def filter(&block) map {|el| yield(el)}.get_or_else { false } ? self : None.new end |
#filter_not(&block) ⇒ RFunc::Option
Filters the Some by the inverse of a given function
50 51 52 |
# File 'lib/rfunc/option.rb', line 50 def filter_not(&block) map {|el| !yield(el) }.get_or_else { false } ? self : None.new end |
#get ⇒ Any
Extracts the value of the option
28 |
# File 'lib/rfunc/option.rb', line 28 def get; @value end |
#is_option?(el) ⇒ Boolean
Tests whether or not an object is an Option
62 63 64 |
# File 'lib/rfunc/option.rb', line 62 def is_option?(el) el.is_a?(AbstractOption) end |