String output method memo in Ruby

ruby-2.7.1p83

Various output methods

There are print, puts, p, pp, printf, etc. when outputting String with ruby. For example

print 'Hello World.'

If you enter, the characters inside''will be output.

print

Output result

1. Hello World.

It is displayed without line breaks in the print method.

puts

In addition to print, if you use puts, it will be output with a line break at the end.

puts 'Hello'
puts 'World.'

Output result

1. Hello
2. World.

p

The output result of the p method is enclosed in "" and displayed as it is. It is used for debugging because the object type information, line feed code, special characters, etc. are output as they are.

p 'Hello World.'
p Hello World.

Output result

1. "Hello World."
2. Hello World.

pp

For pp, output with moderate indentation and line breaks can be obtained.


Recommended Posts

String output method memo in Ruby
Output triangle in Ruby
Ruby design pattern template method pattern memo
[Ruby] undefined method `dark?'occurs in rqr_code
Ruby memo
[Technical memo] What is "include" in Ruby?
Implemented "Floyd Cycle Detection Method" in Ruby
Ruby print puts p printf output method
ruby Exercise Memo II (variable and method)
Ruby input / output
Ruby to_s method
[ruby] drill output
Class in Ruby
[Ruby] slice method
Ruby standard output
[Ruby] end_with? method
[Ruby] Method memorandum
[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
Heavy in Ruby! ??
[Ruby] initialize method
Ruby build method
[wip] Ruby memo
Ruby accessor method
ruby map method
About regular expressions used in ruby sub method
[Ruby] Cut out a string using the slice method
[Ruby] How to use standard output in conditional branching
Ruby Learning # 30 Initialize Method
abbreviation for ruby method
About eval in Ruby
Examine the elements in the array using the [Ruby] includes? Method
Java learning memo (method)
Ruby Learning # 24 Exponent Method
ruby basic syntax memo
[Java ~ Method ~] Study memo (5)
Data acquisition method memo when there is HashMap in HashMap
definition of ruby method
Ruby calorie calculation output
[For beginners] ○○. △△ in Ruby (ActiveRecord method, instance method, data acquisition)
Variable type in ruby
[Ruby] Method definition summary
Output in multiples of 3
Fast popcount in Ruby
Various Ruby string operations
[Ruby] Get in the habit of using the dup method when making a copy of a string variable
[Ruby] Count an even number in an array using the even? Method
How to change a string in an array to a number in Ruby
In Ruby you can define a method with any name
ABC177 --solving E in Ruby
Validate JWT token in Ruby
Read design patterns in Ruby
Ruby study memo (conditional branching)
Output about the method Part 1
Write class inheritance in Ruby
Code entry method in Qiita
Convert to Ruby Leet string
Java Silver Study Method Memo
[Self-use memo] (Ruby) class, class instance, instance