Class: With

Inherits:
Object show all
Defined in:
lib/with.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.object(the_object, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/with.rb', line 6

def self.object(the_object, &block)
  @the_object = the_object
  @original_context = block.binding 
  
  anonymous_class = Class.new
  anonymous_class.instance_eval { define_method("the_block", block) }
  anonymous_class_as_sexp = ParseTree.translate(anonymous_class)
  
  our_block_sexp = anonymous_class_as_sexp[3][2][2]
  our_block_sexp = transform(our_block_sexp)
  
  transformed_block = lambda { eval(WithSexpProcessor.new.process(our_block_sexp)) } #, block.binding) }
  transformed_block.call
end