Skip to content

Instantly share code, notes, and snippets.

@ralphos
Created April 30, 2012 14:02
Show Gist options
  • Save ralphos/2558568 to your computer and use it in GitHub Desktop.
Save ralphos/2558568 to your computer and use it in GitHub Desktop.
temp.rb_v2
s = "Welcome to the forum.\nHere you can learn Ruby.\nAlong with other members.\n"
def add_index(lines)
indexed_lines = []
lines.each_line.with_index(offset = 1) do |line, index|
indexed_lines << "Line #{index}: #{line}"
end
indexed_lines
end
lines = add_index(s)
lines.each { |line| puts line }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment