1

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!

2 Answers 2

1

use:

puts "Hey! What's up?"

crypt = gets.chomp

p [crypt.split("")]
Sign up to request clarification or add additional context in comments.

Comments

0

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"]]

1 Comment

Thanks for responding, Ed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.