diff options
author | Tristan Hume <tristan@thume.ca> | 2013-08-12 15:05:00 -0400 |
---|---|---|
committer | Tristan Hume <tristan@thume.ca> | 2013-08-12 15:05:00 -0400 |
commit | 5c5c8d3c4a0aea7c1c7a8150f428e354d0a12a6c (patch) | |
tree | 0b0e91b7e7cb6b1f7aa96fb48c34637b2567156e | |
parent | 5424b31848e85e40ea78afb4582e8f33845e1b01 (diff) |
Tidy up wording
-rw-r--r-- | ruby.html.markdown | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown index 52321ff6..68c5b524 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -187,14 +187,14 @@ end #=> iteration 4 #=> iteration 5 -# HOWEVER -# No-one uses for loops -# Under the hood for loops use the each method which takes a "block". -# A block is a bunch of code that you can pass to a method like each. +# HOWEVER, No-one uses for loops. +# Instead you should use the "each" method and pass it a block. +# A block is a bunch of code that you can pass to a method like "each". # It is analogous to lambdas, anonymous functions or closures in other programming languages. - -# The each method runs the block multiple times passing a counter. -# You can iterate over a range like this: +# +# The "each" method of a range runs the block once for each element of the range. +# The block is passed a counter as a parameter. +# Calling the "each" method with a block looks like this: (1..5).each do |counter| puts "iteration #{counter}" @@ -208,7 +208,7 @@ end # You can also surround blocks in curly brackets: (1..5).each {|counter| puts "iteration #{counter}"} -# You can also iterate over the contents of data structures using each. +# The contents of data structures can also be iterated using each. array.each do |element| puts "#{element} is part of the array" end |