Permalink
Browse files

Add for statement processing + explanation

  • Loading branch information...
1 parent c98c972 commit 5e34804dcb5f69e243374aeccb612d0d07ef375d @radar radar committed Sep 20, 2010
Showing with 22 additions and 0 deletions.
  1. BIN explanations/.for.md.swp
  2. +4 −0 explanations/for.md
  3. +4 −0 fixtures/for.rb
  4. +14 −0 processor.rb
Binary file not shown.
View
@@ -0,0 +1,4 @@
+## `for` statement
+
+A `for` statement is used for iterating over a collection of objects. The code between the `for` statement and its matching `end` will be ran for every element in the specified collection, defining a local variable for every object for each time the block is ran.
+
View
@@ -0,0 +1,4 @@
+a = [1,2,3]
+for e in a
+ puts e
+end
View
@@ -143,6 +143,20 @@ def process_lit(exp)
super
end
end
+
+ # Stolen from within Ruby2Ruby
+ # Massacred to remove the useless do after the collection
+ def process_for(exp)
+ recv = process exp.shift
+ iter = process exp.shift
+ body = exp.empty? ? nil : process(exp.shift)
+
+ result = ["for #{iter.gsub("\n", "")} in #{recv}"]
+ result << indent(body ? body : "# do nothing")
+ result << "end"
+
+ mark(:for) + result.join("\n")
+ end
CALLS = [:require, :attr_accessor, :attr_reader, :attr_writer, :include, :extend]
SPECIALS = [:colon2]

0 comments on commit 5e34804

Please sign in to comment.