User Program Communication

Print in Ruby

Used output to the console.


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

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

Notes

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.


Example
name = 'Yukihiro'

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

See Also
Documentation

Ruby Docs - Module: Kernal - Print

Add to Slack

< Class Methods   |   User Input >

© 2018 SyntaxDB. All Rights Reserved.