puts is Ruby’s everyday output method. It writes a value to an output stream and normally appends a newline, making each printed line begin after the previous one. If the value already ends with a newline, puts does not add another. section 1.1.6
Use puts to produce readable line-oriented output:
- puts can write calculated values as well as strings. section 1.1.6
- Use print when adjacent output must remain on the same line; a trailing newline must then be supplied explicitly. section 1.1.6
- Calling puts on an open file handle, such as fh.puts fahrenheit, writes the value to that file rather than the screen. section 1.1.7
- In irb, puts displays its output and returns nil, so irb may show both the printed line and => nil. section 1.4.2
Printing a conversion result
celsius = gets.to_i fahrenheit = (celsius * 9 / 5) + 32 puts "The Fahrenheit equivalent is #{fahrenheit}." section 1.1.7
