User Program Communication

User Input in Ruby

Used to get information from the user during runtime.


Syntax
variable = gets #includes newline character, or \n

variable = gets.chomp #'chomps' newline character

Notes

The 'gets' keyword must be used with the assignment operator.


Example
puts "What is your name?"
name = gets.chomp
puts "Welcome, #{name}!"

< Print   |   Commenting >

© 2018 SyntaxDB. All Rights Reserved.