Class: Mercury::Cps::SeqWithLet

Inherits:
Object
  • Object
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.



43
44
45
# File 'lib/mercury/cps/seq_with_let.rb', line 43

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



51
52
53
# File 'lib/mercury/cps/seq_with_let.rb', line 51

def method_missing(name, *args, &block)
  __values.fetch(name) { __parent_call(name.to_s, *args, &block) }
end

Instance Method Details

#__chainObject



47
48
49
# File 'lib/mercury/cps/seq_with_let.rb', line 47

def __chain
  @__chain ||= Cps.identity
end

#__parent_call(name, *args, &block) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/mercury/cps/seq_with_let.rb', line 55

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

#__valuesObject



64
65
66
# File 'lib/mercury/cps/seq_with_let.rb', line 64

def __values
  @__values ||= {}
end

#and_lift(&block) ⇒ Object



31
32
33
# File 'lib/mercury/cps/seq_with_let.rb', line 31

def and_lift(&block)
  @__chain = __chain.and_lift(&block)
end

#and_then(&block) ⇒ Object



27
28
29
# File 'lib/mercury/cps/seq_with_let.rb', line 27

def and_then(&block)
  @__chain = __chain.and_then(&block)
end

#let(name, &block) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/mercury/cps/seq_with_let.rb', line 35

def let(name, &block)
  and_then(&block)
  and_then do |value|
    __values[name] = value
    Cps.lift{value}
  end
end