Lately I have been going through some Ruby books and I keep coming up on
an script like the following:
hash={"A"=>10, "B"=>20, "C"=>30}
p hash.keys() # what is this
What is this p method or expression I keep coming across? I understand
that this is some kind of print statement, but that is all I understand
about this statement.
I have tried doing a google search, but since I cannot defined what
this expression is I have not found a vaild result. Can someone please
explain what this [p] expression or method is??
On Thu, Jul 5, 2012 at 10:29 AM, smoothedatol412 @gmail.com <lists@ruby-forum.com> wrote:
Lately I have been going through some Ruby books and I keep coming up on
an script like the following:
hash={"A"=>10, "B"=>20, "C"=>30}
p hash.keys() # what is this
What is this p method or expression I keep coming across? I understand
that this is some kind of print statement, but that is all I understand
about this statement.
I have tried doing a google search, but since I cannot defined what
this expression is I have not found a vaild result. Can someone please
explain what this [p] expression or method is??
Its just a short hand version of [puts object.insect()]? I want to ask
but I start using it in notes or in code, and I have been learning or
thing its one thing when it is another...
I did not know that people were still commenting this topic..
Anyways, I do not like the short hand version of using this type of
statement in ruby when I tried to use it in test scripts.
# short example
var=10
p var
I have choose to use the following statement instead
var=10
puts var.inspect()
I have come from Java and a few other programming backgrounds and I am
use to the compiled langs, like C and Java. I like coding things
out the long way since it is easy to go back later on and easily find
that bug code that is creating problems for the program.
While I generally sympathize with that approach (making things
explicit) I don't agree in this particular case. You'll find "p var"
as easily as "puts var.inspect" - but it's far less typing.
Cheers
robert
···
On Sun, Jul 8, 2012 at 11:39 AM, smoothedatol412 @gmail.com <lists@ruby-forum.com> wrote:
I did not know that people were still commenting this topic..
Anyways, I do not like the short hand version of using this type of
statement in ruby when I tried to use it in test scripts.
# short example
var=10
p var
I have choose to use the following statement instead
var=10
puts var.inspect()
I have come from Java and a few other programming backgrounds and I am
use to the compiled langs, like C and Java. I like coding things
out the long way since it is easy to go back later on and easily find
that bug code that is creating problems for the program.
On Sun, Jul 8, 2012 at 11:39 AM, smoothedatol412 @gmail.com
I have come from Java and a few other programming backgrounds and I am
use to the compiled langs, like C and Java. I like coding things
out the long way since it is easy to go back later on and easily find
that bug code that is creating problems for the program.
While I generally sympathize with that approach (making things
explicit) I don't agree in this particular case. You'll find "p var"
as easily as "puts var.inspect" - but it's far less typing.
Not to mention the convenience (with a single extra require) of
changing "p var" to "pp var", especially in the absence of
var.pretty_inspect
···
On 9 July 2012 16:09, Robert Klemme <shortcutter@googlemail.com> wrote: