When I make a new array/hash in irb, it prints out a nice format to show the structure, ex.
["value1", "value2", "value3"] {"key1" => "value1"}
... but when I try to print out my variables using puts
, I get them collapsed:
value1 value2 value3 key1 value1
I gather that puts
is not the right command for what I want, but what is? I want to be able to view my variables in irb in the first format, not the second.
You can either use the inspect
method:
a=["value1", "value2", "value3"] puts a.inspect
Or, even better, use the pp (pretty print) lib:
require 'pp' a=["value1", "value2", "value3"] pp a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With