Ruby P puts print

Source: Internet
Author: User

Ruby has several methods for outputting data to the console. The most common methods are P, puts, and print. I will check the differences between these methods every time I use them, but I forgot to do it some time later... So record it here. You can find it next time :)

After the puts method is output, it will automatically wrap the line (if the output string itself contains a line break, puts will not add additional line breaks) and will escape. Puts can accept multiple parameters, and each parameter is output into a separate row. Kernel puts = $ stdout. Puts

Print does not wrap By default (so when multiple parameters are accepted, the output is still a whole line) and will not be escaped. Directly Using print will output $ _. But print will be affected by $, (separator) and $ \ (line tail character.

Print "A", "B", "C" # => ABC $, = "," $ \ = "\ n" print "A", "B ", "C" # => A, B, C \ n

Other aspects are similar to puts.

P is basically equivalent to puts obj. inspect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.