Reputation: 177
Ruby noob here. I've been on this for a couple of hours while, but I can't figure out how to store user input, turn it into an array, and then split the array into separate elements.
puts "Hey! What's up?"
response = Array.new
response << gets.chomp
crypt = response.each_slice(3).to_a
print crypt
This is what is outputted:
Hey! What's up?
Nothin
[["Nothin"]]
This is what I want, but can't figure out:
[["N", "o", "t", "h", "i", "n"]]
I've looked at Ruby docs but got confused, so after several hours of trial and error I'm here. Thanks for the help!
Upvotes: 1
Views: 811
Reputation: 3723
This is how I'd do to get what you need:
puts "Hey! What's up?"
response = Array.new
input = gets.chomp
response << input.split("")
puts response.to_s
Running this code you'll get
Hey! What's up?
Nothin
[["N", "o", "t", "h", "i", "n"]]
Upvotes: 0