Class: Blank

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wrapped/blank.rb

Overview

The class represents a lack of something.

Instance Method Summary collapse

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.

Returns:

  • (Boolean)


49
50
51
# File 'lib/wrapped/blank.rb', line 49

def blank?
  true
end

#eachObject

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_mapObject

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

#fmapObject

Do nothing, returning itself.

> w.fmap {|n| n+1 }



63
64
65
# File 'lib/wrapped/blank.rb', line 63

def fmap
  self
end

#presentObject

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.

Returns:

  • (Boolean)


44
45
46
# File 'lib/wrapped/blank.rb', line 44

def present?
  false
end

#unwrapObject

It is an error (specifically, an IndexError) to use this method.

Raises:

  • (IndexError)


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