Class: SomeClass

Inherits:
OptionClass show all
Defined in:
lib/option.rb

Instance Method Summary collapse

Methods inherited from OptionClass

#==

Constructor Details

#initialize(value) ⇒ SomeClass

Returns a new instance of SomeClass.



25
26
27
# File 'lib/option.rb', line 25

def initialize(value)
  @value = value
end

Instance Method Details

#each(&blk) ⇒ Object



41
42
43
44
45
# File 'lib/option.rb', line 41

def each(&blk)
  blk.call(get)

  nil
end

#empty?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/option.rb', line 55

def empty?
  false
end

#error(*argv) ⇒ Object



99
100
101
# File 'lib/option.rb', line 99

def error(*argv)
  self
end

#exists?(&blk) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/option.rb', line 71

def exists?(&blk)
  !! blk.call(get)
end

#filter(&blk) ⇒ Object



79
80
81
# File 'lib/option.rb', line 79

def filter(&blk)
  exists?(&blk) ? self : None
end

#flat_map(&blk) ⇒ Object



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

def flat_map(&blk)
  assert_option(blk.call(get))
end

#flattenObject



92
93
94
95
96
97
# File 'lib/option.rb', line 92

def flatten
  case get
    when OptionClass then get.flatten
    else self
  end
end

#fold(if_empty, &blk) ⇒ Object



67
68
69
# File 'lib/option.rb', line 67

def fold(if_empty, &blk)
  blk.call(get)
end

#getObject



33
34
35
# File 'lib/option.rb', line 33

def get
  @value
end

#get_or_else(&blk) ⇒ Object



37
38
39
# File 'lib/option.rb', line 37

def get_or_else(&blk)
  get
end

#include?(value) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/option.rb', line 75

def include?(value)
  get == value
end

#inside(&blk) ⇒ Object



83
84
85
86
# File 'lib/option.rb', line 83

def inside(&blk)
  blk.call(get)
  self
end

#map(&blk) ⇒ Object



59
60
61
# File 'lib/option.rb', line 59

def map(&blk)
  self.class.new(blk.call(get))
end

#or_else(&blk) ⇒ Object



88
89
90
# File 'lib/option.rb', line 88

def or_else(&blk)
  self
end

#or_nilObject



47
48
49
# File 'lib/option.rb', line 47

def or_nil
  get
end

#present?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/option.rb', line 51

def present?
  true
end

#to_aObject



29
30
31
# File 'lib/option.rb', line 29

def to_a
  [get]
end