Ruby Beauty – Iteration with an Index
I just love how expressive and clean Ruby’s syntax is. How often do you need to iterate over a collection and get a count as well? That sort of code is ugly in something like C#, but in Ruby:
people = %w{Dave Bill Mike Mark John} # Simple collection of names
people.each_with_index { |name, index| puts "#{index}: #{name}" }
And that displays:
0: Dave
1: Bill
2: Mike
3: Mark
4: John
each_with_index - simple and elegant.
And what’s the C# version of something like this look like? Blah :)