Class: Just
Instance Method Summary
collapse
Methods inherited from Maybe
from
Constructor Details
#initialize(value) ⇒ Just
Returns a new instance of Just.
11
12
13
|
# File 'lib/matilda-maybe/just.rb', line 11
def initialize(value)
@value = value
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
2
3
4
5
6
7
8
9
|
# File 'lib/matilda-maybe/just.rb', line 2
def method_missing(method_name, *args, &block)
values = args.map { |arg|
return Nothing.new if arg == Nothing.new
arg.kind_of?(Just) ? arg.value : arg
}
Just.new(@value.public_send(method_name, *values, &block))
end
|
Instance Method Details
#==(object) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/matilda-maybe/just.rb', line 33
def ==(object)
if object.class == Just
object.value == self.value
else
false
end
end
|
#bind(&block) ⇒ Object
15
16
17
18
19
|
# File 'lib/matilda-maybe/just.rb', line 15
def bind(&block)
computed = block.call(@value)
warn("Not returning a Maybe from #bind is really bad form...") unless computed.kind_of?(Maybe)
computed
end
|
#get(*args, &block) ⇒ Object
29
30
31
|
# File 'lib/matilda-maybe/just.rb', line 29
def get(*args, &block)
@value
end
|
#map(&block) ⇒ Object
21
22
23
|
# File 'lib/matilda-maybe/just.rb', line 21
def map(&block)
Just.new(block.call(@value))
end
|
#or(*args, &block) ⇒ Object
25
26
27
|
# File 'lib/matilda-maybe/just.rb', line 25
def or(*args, &block)
self
end
|