Skip to content

Instantly share code, notes, and snippets.

Created January 7, 2014 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8308733 to your computer and use it in GitHub Desktop.
Save anonymous/8308733 to your computer and use it in GitHub Desktop.
def prompt
print '> '
end
def counter(maxcount)
numbers = []
for i in maxcount
puts "At the top of i is #{i}"
numbers.push(i)
i += 1
puts "Numbers now: #{numbers}"
puts "At the bottom of i is #{i}"
end
end
prompt; counter(0..5)
# how do i get this to accept user input without throwing errors?
# I've tried counter(gets.to_i) but error is thrown in that case:
# rub27.rb:6:in `counter': undefined method `each' for 4:Fixnum (NoMethodError)
# from rub27.rb:15:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment