Class: Mercury::Cps::SeqWithLet
- Inherits:
-
Object
- Object
- Mercury::Cps::SeqWithLet
show all
- Defined in:
- lib/mercury/cps/seq_with_let.rb
Instance Method Summary
collapse
Constructor Details
#initialize(parent_binding) ⇒ SeqWithLet
Returns a new instance of SeqWithLet.
41
42
43
|
# File 'lib/mercury/cps/seq_with_let.rb', line 41
def initialize(parent_binding)
@__parent_binding = parent_binding
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
49
50
51
|
# File 'lib/mercury/cps/seq_with_let.rb', line 49
def method_missing(name, *args, &block)
__values.fetch(name) { __parent_call(name.to_s, *args, &block) }
end
|
Instance Method Details
#__chain ⇒ Object
45
46
47
|
# File 'lib/mercury/cps/seq_with_let.rb', line 45
def __chain
@__chain ||= Cps.identity
end
|
#__parent_call(name, *args, &block) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/mercury/cps/seq_with_let.rb', line 53
def __parent_call(name, *args, &block)
@__parent_caller ||= @__parent_binding.eval <<-EOD
proc do |name, *args, &block|
send(name, *args, &block)
end
EOD
@__parent_caller.call(name, *args, &block)
end
|
#__values ⇒ Object
62
63
64
|
# File 'lib/mercury/cps/seq_with_let.rb', line 62
def __values
@__values ||= {}
end
|
#and_lift(&block) ⇒ Object
29
30
31
|
# File 'lib/mercury/cps/seq_with_let.rb', line 29
def and_lift(&block)
@__chain = __chain.and_lift(&block)
end
|
#and_then(&block) ⇒ Object
25
26
27
|
# File 'lib/mercury/cps/seq_with_let.rb', line 25
def and_then(&block)
@__chain = __chain.and_then(&block)
end
|
#let(name, &block) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/mercury/cps/seq_with_let.rb', line 33
def let(name, &block)
and_then(&block)
and_then do |value|
__values[name] = value
Cps.lift{value}
end
end
|