p vs. print

  • Thread starter Abder-Rahman Ali
  • Start date
R

Rob Biedenharn

irb(main):003:0> print [1, 2, 3]
[1, 2, 3]=> nil

Are you sure about that? I get this:

irb(main):001:0> print [1, 2, 3]
123=> nil

The result you showed should probably be produced by:

print [1, 2, 3].inspect


It all depends on what ruby you're using:

$ rvm ruby -e 'a=[1,2,3];puts "to_s",a.to_s; puts "inspect",a.inspect'
info: jruby-1.5.1: jruby 1.5.1 (ruby 1.8.7 patchlevel 249) (2010-06-06
f3a3480) (Java HotSpot(TM) Client VM 1.5.0_24) [i386-java]

Unable to find a $JAVA_HOME at "/usr", continuing with system-provided
Java...
to_s
123
inspect
[1, 2, 3]

info: ree-1.8.7-head: ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-
darwin9.8.0]

to_s
123
inspect
[1, 2, 3]

info: ruby-1.8.6-p383: ruby 1.8.6 (2009-08-04 patchlevel 383) [i686-
darwin9.8.0]

to_s
123
inspect
[1, 2, 3]

info: ruby-1.9.1-p378: ruby 1.9.1p378 (2010-01-10 revision 26273)
[i386-darwin9.8.0]

to_s
[1, 2, 3]
inspect
[1, 2, 3]

info: ruby-1.9.2-p0: ruby 1.9.2p0 (2010-08-18 revision 29036) [i386-
darwin9.8.0]

to_s
[1, 2, 3]
inspect
[1, 2, 3]


So you might both be "right" on this.

-Rob

Rob Biedenharn
(e-mail address removed) http://AgileConsultingLLC.com/
(e-mail address removed) http://GaslightSoftware.com/
 
J

Josh Cheek

[Note: parts of this message were removed to make it a legal post.]

irb(main):003:0> print [1, 2, 3]
[1, 2, 3]=> nil

Are you sure about that? I get this:

irb(main):001:0> print [1, 2, 3]
123=> nil

The result you showed should probably be produced by:

print [1, 2, 3].inspect

Differences in versions. You can get an account at
http://ruby-versions.net/and play around like this



$ rvm ruby-1.8.6-p399,ruby-1.8.7-p174,ruby-1.9.1-p378,ruby-1.9.2-p0 -e
'print [1,2,3]'

info: ruby-1.8.6-p399: ruby 1.8.6 (2010-02-05 patchlevel 399) [x86_64-linux]


123
info: ruby-1.8.7-p174: ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]


123
info: ruby-1.9.1-p378: ruby 1.9.1p378 (2010-01-10 revision 26273)
[x86_64-linux]

[1, 2, 3]
info: ruby-1.9.2-p0: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]


[1, 2, 3]



Going back further, it has been '123' as far back as Ruby 1.0

$ ruby-1.0 -e 'print [1,2,3]'
123
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,373
Latest member
Desiree036

Latest Threads

Top