Class: Blank
Overview
The class represents a lack of something.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Is this wrapped value equal to the given wrapped value? All blank values are equal to each other.
-
#blank(&block) ⇒ Object
Call the block then return itself.
-
#blank? ⇒ Boolean
True; this is an instance of nothing.
-
#each ⇒ Object
Produce the empty list.
-
#flat_map ⇒ Object
Do nothing, returning itself.
-
#fmap ⇒ Object
Do nothing, returning itself.
-
#present ⇒ Object
Does nothing, returning itself.
-
#present? ⇒ Boolean
False; this is not an instance of a wrapped value.
-
#unwrap ⇒ Object
It is an error (specifically, an IndexError) to use this method.
-
#unwrap_or(default) ⇒ Object
Produce the value that is passed in.
Instance Method Details
#==(other) ⇒ Object
Is this wrapped value equal to the given wrapped value? All blank values are equal to each other.
> nil.wrapped == nil.wrapped > 1.wrapped == nil.wrapped
72 73 74 |
# File 'lib/wrapped/blank.rb', line 72 def ==(other) other.blank? end |
#blank(&block) ⇒ Object
Call the block then return itself. This is chainable. See present for its companion.
w.blank { puts “I got nothing” }.present {|n| puts “got #{n}” }
29 30 31 32 |
# File 'lib/wrapped/blank.rb', line 29 def blank(&block) block.call self end |
#blank? ⇒ Boolean
True; this is an instance of nothing.
49 50 51 |
# File 'lib/wrapped/blank.rb', line 49 def blank? true end |
#each ⇒ Object
Produce the empty list.
This class mixes in the Enumerable module, which relies on this.
> w.each {|n| puts n }
39 40 41 |
# File 'lib/wrapped/blank.rb', line 39 def each [] end |
#flat_map ⇒ Object
Do nothing, returning itself.
> w.flat_map {|n| n+1 }
56 57 58 |
# File 'lib/wrapped/blank.rb', line 56 def flat_map self end |
#fmap ⇒ Object
Do nothing, returning itself.
> w.fmap {|n| n+1 }
63 64 65 |
# File 'lib/wrapped/blank.rb', line 63 def fmap self end |
#present ⇒ Object
Does nothing, returning itself. This is chainable. See blank for its companion.
w.present.blank { puts “Missing” }
21 22 23 |
# File 'lib/wrapped/blank.rb', line 21 def present self end |
#present? ⇒ Boolean
False; this is not an instance of a wrapped value.
44 45 46 |
# File 'lib/wrapped/blank.rb', line 44 def present? false end |
#unwrap ⇒ Object
It is an error (specifically, an IndexError) to use this method.
6 7 8 |
# File 'lib/wrapped/blank.rb', line 6 def unwrap raise IndexError.new("Blank has no value") end |
#unwrap_or(default) ⇒ Object
Produce the value that is passed in.
> w.unwrap_or(0)
13 14 15 |
# File 'lib/wrapped/blank.rb', line 13 def unwrap_or(default) default end |