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
(also: #collect, #map)
Do nothing, returning itself.
-
#grep ⇒ Object
Produces itself.
-
#present ⇒ Object
Does nothing, returning itself.
-
#present? ⇒ Boolean
False; this is not an instance of a wrapped value.
-
#reject ⇒ Object
Produces itself.
-
#select ⇒ Object
(also: #find_all)
Produces itself.
-
#unwrap ⇒ Object
It is an error (specifically, an IndexError) to use this method.
-
#unwrap_or(default = nil) ⇒ 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
96 97 98 |
# File 'lib/wrapped/blank.rb', line 96 def ==(other) other.is_a?(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}” }
33 34 35 36 |
# File 'lib/wrapped/blank.rb', line 33 def blank(&block) block.call self end |
#blank? ⇒ Boolean
True; this is an instance of nothing.
70 71 72 |
# File 'lib/wrapped/blank.rb', line 70 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 }
43 44 45 |
# File 'lib/wrapped/blank.rb', line 43 def each self end |
#flat_map ⇒ Object
Do nothing, returning itself.
> w.flat_map {|n| n+1 }
77 78 79 |
# File 'lib/wrapped/blank.rb', line 77 def flat_map self end |
#fmap ⇒ Object Also known as: collect, map
Do nothing, returning itself.
> w.fmap {|n| n+1 }
84 85 86 |
# File 'lib/wrapped/blank.rb', line 84 def fmap self end |
#grep ⇒ Object
Produces itself.
60 61 62 |
# File 'lib/wrapped/blank.rb', line 60 def grep(*) self end |
#present ⇒ Object
Does nothing, returning itself. This is chainable. See blank for its companion.
w.present.blank { puts “Missing” }
25 26 27 |
# File 'lib/wrapped/blank.rb', line 25 def present self end |
#present? ⇒ Boolean
False; this is not an instance of a wrapped value.
65 66 67 |
# File 'lib/wrapped/blank.rb', line 65 def present? false end |
#reject ⇒ Object
Produces itself.
55 56 57 |
# File 'lib/wrapped/blank.rb', line 55 def reject self end |
#select ⇒ Object Also known as: find_all
Produces itself.
48 49 50 |
# File 'lib/wrapped/blank.rb', line 48 def select self 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 = nil) ⇒ Object
Produce the value that is passed in.
> w.unwrap_or(0)
13 14 15 16 17 18 19 |
# File 'lib/wrapped/blank.rb', line 13 def unwrap_or(default = nil) if block_given? yield else default end end |