Can I assume that the following inconsistency (See the diff between cmd 1
and cmd 2) has something to do with the eval-print loop in IRB and not
something internal to Ruby (after all, cmd 3 works)?
···
irb(main):021:0> print “some string with blanks”.intern
some string with blanksnil
irb(main):022:0> p (“some string with blanks”.intern)
:some string with blanks
nil
irb(main):023:0> print “some string with blanks”.intern == (“some string
with blanks”.intern) ? “Equal” : “Not Equal”
Equalnil
±-----------------------------------------------+
DREW MILLS | 10101 Linn Station Rd. |
> Suite 800 | tamills@ups.com | Louisville, KY 40223 |
Technical Specialist | 502-394-7785 |
United Parcel Service | 502-394-7812 |
±-----------------------------------------------+
Can I assume that the following inconsistency (See the diff between cmd 1
and cmd 2) has something to do with the eval-print loop in IRB and not
something internal to Ruby (after all, cmd 3 works)?
irb(main):021:0> print “some string with blanks”.intern
some string with blanksnil
irb(main):022:0> p (“some string with blanks”.intern)
:some string with blanks
nil
irb(main):023:0> print “some string with blanks”.intern == (“some string
with blanks”.intern) ? “Equal” : “Not Equal”
Equalnil
It’s not inconsistent; print and p often give you different
representations.
Can I assume that the following inconsistency (See the diff between cmd 1
and cmd 2) has something to do with the eval-print loop in IRB and not
something internal to Ruby (after all, cmd 3 works)?
no,
-----------------------------------------------------------------
irb(main):021:0> print "some string with blanks".intern
some string with blanksnil
#print call #to_s
pigeon% ruby -e 'p :name.to_s'
"name"
pigeon%
irb(main):022:0> p ("some string with blanks".intern)
:some string with blanks
Can I assume that the following inconsistency (See the diff between cmd 1
and cmd 2) has something to do with the eval-print loop in IRB and not
something internal to Ruby (after all, cmd 3 works)?
I’m not sure what you meant by “inconsistency”.
irb(main):021:0> print “some string with blanks”.intern
some string with blanksnil
“print” prints symbols by “to_s”. So printed string is “some string
with blanks”, and its returned value is “nil”
irb(main):022:0> p (“some string with blanks”.intern)
:some string with blanks
nil
“p” prints symbols by “intern” with a newline. So printed string is
“:some string with blanks\n”, and its returned value is “nil”
irb(main):023:0> print “some string with blanks”.intern == (“some string
with blanks”.intern) ? “Equal” : “Not Equal”
Equalnil
So even though their representation is different, they are still same
symbols.
matz.
···
In message “Inconsistency while playing with Symbol in IRB” on 02/12/04, “Mills Thomas (app1tam)” app1tam@ups.com writes:
Can I assume that the following inconsistency (See the diff between cmd 1
and cmd 2) has something to do with the eval-print loop in IRB and not
something internal to Ruby (after all, cmd 3 works)?
irb(main):021:0> print “some string with blanks”.intern
some string with blanksnil
irb(main):022:0> p (“some string with blanks”.intern)
:some string with blanks
nil
p != print
irb(main):001:0> print “bla bla”.intern
bla blanil
irb(main):002:0> print (“bla bla”.intern)
bla blanil
irb(main):003:0> p “bla bla”.intern
:bla bla
nil
irb(main):004:0> p(“bla bla”.intern)
:bla bla
nil
···
On Wed, Dec 04, 2002 at 01:49:41AM +0900, Mills Thomas (app1tam) wrote:
irb(main):023:0> print “some string with blanks”.intern == (“some string
with blanks”.intern) ? “Equal” : “Not Equal”
Equalnil
±-----------------------------------------------+
DREW MILLS | 10101 Linn Station Rd. |
> Suite 800 | tamills@ups.com | Louisville, KY 40223 |
Technical Specialist | 502-394-7785 |
United Parcel Service | 502-394-7812 |
±-----------------------------------------------+