User Program Communication

Print in Ruby

Used output to the console.

# does not automatically add a new line
print "content", variable, "content #{variable}"

# adds a new line
puts "content", variable, "content #{variable}"


A comma, or a plus sign can be used to concatenate items.

#{variable} is used to embed contents of a variable within a string. This is considered the best practice when dealing with variables.

name = 'Yukihiro'

puts "Hello, #{name}!" #will output 'Hello, Yukihiro!'

See Also

Ruby Docs - Module: Kernal - Print

Add to Slack

< Class Methods   |   User Input >

© 2019 SyntaxDB. All Rights Reserved.