Class: RFunk::Some

Inherits:
Option show all
Defined in:
lib/rfunk/maybe/some.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Option

inherited

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



15
16
17
# File 'lib/rfunk/maybe/some.rb', line 15

def initialize(value)
  @value = value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



31
32
33
# File 'lib/rfunk/maybe/some.rb', line 31

def method_missing(method, *arguments, &block)
  RFunk.option(value.send(method, *arguments, &block))
end

Instance Attribute Details

#valueObject (readonly) Also known as: identity

Returns the value of attribute value.



13
14
15
# File 'lib/rfunk/maybe/some.rb', line 13

def value
  @value
end

Class Method Details

.create(value) ⇒ Object



4
5
6
# File 'lib/rfunk/maybe/some.rb', line 4

def create(value)
  new(value)
end

.satisfies?(value) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/rfunk/maybe/some.rb', line 8

def satisfies?(value)
  !value.nil?
end

Instance Method Details

#<=>(other) ⇒ Object



39
40
41
# File 'lib/rfunk/maybe/some.rb', line 39

def <=>(other)
  value <=> other.value
end

#==(other) ⇒ Object



35
36
37
# File 'lib/rfunk/maybe/some.rb', line 35

def ==(other)
  value == other.value
end

#coerce(other) ⇒ Object



43
44
45
# File 'lib/rfunk/maybe/some.rb', line 43

def coerce(other)
  [other, value]
end

#keyObject



49
50
51
# File 'lib/rfunk/maybe/some.rb', line 49

def key
  :some
end

#or(_) ⇒ Object



21
22
23
# File 'lib/rfunk/maybe/some.rb', line 21

def or(_)
  self
end

#pipe(&block) ⇒ Object



25
26
27
28
29
# File 'lib/rfunk/maybe/some.rb', line 25

def pipe(&block)
  return self if block.nil?

  RFunk.option(yield value)
end