Class: RFunk::Some
- Inherits:
-
Option
show all
- Extended by:
- Forwardable
- Defined in:
- lib/rfunk/maybe/some.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #identity)
readonly
Returns the value of attribute value.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Option
#each, inherited
Constructor Details
#initialize(value) ⇒ Some
Returns a new instance of Some.
17
18
19
|
# File 'lib/rfunk/maybe/some.rb', line 17
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
32
33
34
|
# File 'lib/rfunk/maybe/some.rb', line 32
def method_missing(method, *arguments, &block)
RFunk.option(value.send(method, *arguments, &block))
end
|
Instance Attribute Details
#value ⇒ Object
Also known as:
identity
Returns the value of attribute value.
15
16
17
|
# File 'lib/rfunk/maybe/some.rb', line 15
def value
@value
end
|
Class Method Details
.create(value) ⇒ Object
6
7
8
|
# File 'lib/rfunk/maybe/some.rb', line 6
def create(value)
new(value)
end
|
.satisfies?(value) ⇒ Boolean
10
11
12
|
# File 'lib/rfunk/maybe/some.rb', line 10
def satisfies?(value)
!value.nil?
end
|
Instance Method Details
#<=>(other) ⇒ Object
41
42
43
|
# File 'lib/rfunk/maybe/some.rb', line 41
def <=>(other)
value <=> other.value
end
|
#==(other) ⇒ Object
36
37
38
39
|
# File 'lib/rfunk/maybe/some.rb', line 36
def ==(other)
return false unless self.class == other.class
value == RFunk.option(other).value
end
|
#coerce(other) ⇒ Object
45
46
47
|
# File 'lib/rfunk/maybe/some.rb', line 45
def coerce(other)
[other, value]
end
|
#key ⇒ Object
51
52
53
|
# File 'lib/rfunk/maybe/some.rb', line 51
def key
:some
end
|
#or(_) ⇒ Object
23
24
25
|
# File 'lib/rfunk/maybe/some.rb', line 23
def or(_)
self
end
|
#pipe(&block) ⇒ Object
27
28
29
30
|
# File 'lib/rfunk/maybe/some.rb', line 27
def pipe(&block)
return self if block.nil?
RFunk.option(yield value)
end
|