Class: Verstehen::List
- Inherits:
-
Object
- Object
- Verstehen::List
- Defined in:
- lib/verstehen/list.rb
Instance Method Summary collapse
- #comprehend ⇒ Object
- #for(*symbols) ⇒ Object
- #if(&condition) ⇒ Object
- #in(&range) ⇒ Object
-
#initialize(&expression) ⇒ List
constructor
A new instance of List.
Constructor Details
Instance Method Details
#comprehend ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/verstehen/list.rb', line 26 def comprehend generated = "" @dimensions.each_with_index do |dimension, i| block_params = dimension.for.collect {|sym| sym.to_s}.join(", ") generated << "for #{block_params} in @context.instance_eval(&@dimensions[#{i}].in)\n" generated << dimension.for.map {|sym| "@context.#{sym} = #{sym}\n" }.join if dimension == @dimensions.last if @dimensions[i].if generated << "if @context.instance_eval(&@dimensions[#{i}].if)\n" end generated << "@result << @context.instance_eval(&@expression)\n" if @dimensions[i].if generated << "end\n" end end end @dimensions.each_with_index do |dimension, i| generated << "end\n" end #puts generated eval generated @result end |
#for(*symbols) ⇒ Object
10 11 12 13 14 |
# File 'lib/verstehen/list.rb', line 10 def for *symbols @dimensions << Dimension.new(symbols) symbols.each { |sym| Context.send(:attr_accessor, sym) } self end |
#if(&condition) ⇒ Object
21 22 23 24 |
# File 'lib/verstehen/list.rb', line 21 def if &condition @dimensions.last.if = condition self end |
#in(&range) ⇒ Object
16 17 18 19 |
# File 'lib/verstehen/list.rb', line 16 def in &range @dimensions.last.in = range self end |