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 what’s up with this?

d="I'm a string!”; d.class

=> nil

nil? Why isn’t 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.

···

--
Posted via http://www.ruby-forum.com/.

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

Er, what? Yes I did. If it weren’t 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, that’s an example. I tested Ruby many ways to confirm it just flat-out doesn’t 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 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.

···

On Mar 10, 2014, at 12:32 , Joel Pearson <lists@ruby-forum.com> wrote:

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 >

···

On Mon, Mar 10, 2014 at 4:50 PM, Dave Howell <groups.2009a@grandfenwick.net> wrote:

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

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

twitter: @hassan

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 2:32 PM, Joel Pearson <lists@ruby-forum.com> wrote:

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

Dave. This is curious. What does

> 'something'.class

Return?

···

On Mon, Mar 10, 2014 at 5:08 PM, Hassan Schroeder < hassan.schroeder@gmail.com> wrote:

On Mon, Mar 10, 2014 at 4:50 PM, Dave Howell > <groups.2009a@grandfenwick.net> 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 >

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
Hassan Schroeder | about.me
twitter: @hassan

--
- Cliff Rosson

And, more to the point, that's an example. I tested Ruby many ways to confirm it just flat-out doesn't 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.

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

···

On Tue, Mar 11, 2014 at 12:50 AM, Dave Howell <groups.2009a@grandfenwick.net> wrote:

On Mar 10, 2014, at 12:32 , Joel Pearson <lists@ruby-forum.com> wrote:

--
[guy, jim].each {|him| remember.him do |as, often| as.you_can - without end}
http://blog.rubybestpractices.com/