Post

Get user input in Ruby!

Getting user input

gets keyword is used to get the user input as a string.

#!/usr/bin/ruby

puts 'what is your name?'
name = gets.chomp
puts "How are you #{name}"

String#chomp method returns string after removing extra line.

This post is licensed under CC BY 4.0 by the author.