- Comprehensive Ruby Programming
- Jordan Hudgens
- 190字
- 2021-07-02 21:13:22
Using p
Another way to print to the console is as follows:
p "B string"
The difference between these two methods is that the former method will not return any value back to you, whereas the latter one will return a value. The following image shows this difference:

You will see that the puts method returns a value of nil:

The second option returns the value.
Though this difference may not be much now, you will discover how important this is as we progress through the course.
Another difference between the two methods is the way they process the array data structure. The p method prints the array in its code form and returns these values back to the user:

On the other hand, the puts method iterates through the collection to display individual values, and as mentioned earlier, this returns a nil value:

The first set of values were printed with the method.
Knowing that both of these methods work with all data types including arrays and collections is important. Understanding these similarities and differences is important, to ensure that you use the right method at the right time.
- Mobile Application Development:JavaScript Frameworks
- Rust編程:入門、實(shí)戰(zhàn)與進(jìn)階
- JMeter 性能測(cè)試實(shí)戰(zhàn)(第2版)
- Bulma必知必會(huì)
- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- Microsoft System Center Orchestrator 2012 R2 Essentials
- 微服務(wù)從小白到專家:Spring Cloud和Kubernetes實(shí)戰(zhàn)
- Building Machine Learning Systems with Python(Second Edition)
- SSM開發(fā)實(shí)戰(zhàn)教程(Spring+Spring MVC+MyBatis)
- Scala編程(第5版)
- Kotlin進(jìn)階實(shí)戰(zhàn)
- 零基礎(chǔ)學(xué)Java第2版
- Flutter for Beginners
- Learning Yeoman
- 軟件工程實(shí)用教程 (第3版)