Strings don't have any class?

When I upgraded a server from 1.8 to 1.9, I expected some of my code to
break. But one of the fails has me really mystified:

a = Object.new; a.class
=> Object
b=5; b.class
=> Fixnum
c=[1,2,3]; > c.class
=> Array

That all looks just like I expected. So whats up with this?

d="I’m a string!; d.class
=> nil

nil? Why isnt it String?

$ ruby -v
ruby 1.9.3p484 (2013-11-22) [i686-linux]

Because that isn’t a valid line of code. You don’t close the
double-quotes.

On Mon, Mar 10, 2014 at 2:32 PM, Joel P. [email protected]
wrote:

Because that isn’t a valid line of code. You don’t close the
double-quotes.

Specifically, the second double quote is actually not the ASCII quote
character used by most programming languages; it’s a closing “curly”
quote.
But I don’t see why that would make irb accept the line and print “=>
nil”.

On Mon, Mar 10, 2014 at 4:50 PM, Dave H.
[email protected] wrote:

At this point, the evidence I have here is that it’s just a gigantic bug in
Ruby.

Which is just absurd. I can’t imagine how you’d screw up your
environment so badly, but it certainly isn’t the version of ruby
that’s the problem:

17:03 ~/$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin11.4.2]
17:03 ~/$ irb
1.9.3-p484 :001 > “something”.class
=> String
1.9.3-p484 :002 > “something”.class == String
=> true
1.9.3-p484 :003 >

Dave. This is curious. What does

‘something’.class

Return?

On Mon, Mar 10, 2014 at 5:08 PM, Hassan S. <

On Mar 10, 2014, at 12:32 , Joel P. [email protected] wrote:

Because that isn’t a valid line of code. You don’t close the
double-quotes.

Er, what? Yes I did. If it werent valid code, it would have thrown an
error, not returned nil.

Oh, I see. Something screwed up the second quotations during the paste.

And, more to the point, thats an example. I tested Ruby many ways to
confirm it just flat-out doesnt work.

something’.class == String
=>false

is another example. What caused me to have to run this silliness down in
the first place was when my case statements started malfunctioning;
case thingamabob
when Fixnum then this-and-that
when String then something-else
when Array then another-option
end
Suddenly my code was unable to figure out what a string was.

At this point, the evidence I have here is that its just a gigantic bug
in Ruby. Installing the just-released 1.9.3p545 version made the problem
go away. Now I just have to figure out how to get Ubuntu to use the
right version . . . sigh.

On Tue, Mar 11, 2014 at 12:50 AM, Dave H.
[email protected] wrote:

On Mar 10, 2014, at 12:32 , Joel P. [email protected] wrote:

Suddenly my code was unable to figure out what a string was.
Yeah, that’s bad.

Here’s an example how you can produce the output you are observing:

$ ruby -e ‘class String; def class;end end; p “foo”.class, 1.class’
nil
Fixnum

As you can see, Fixnum is unaffected but String instances report nil as
class.

At this point, the evidence I have here is that it’s just a gigantic bug in
Ruby. Installing the just-released 1.9.3p545 version made the problem go away. Now
I just have to figure out how to get Ubuntu to use the right version . . . sigh.

No, it must have to do with your environment as Hassan said already.
You seem to be on Apple; there have been numerous reports that Ruby
and Applet are a difficult couple. Maybe it has something to do with
that.

$ ruby -e ‘p “foo”.class’
String

What happens if you do that?

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs