Forum: Ruby Re: How to find out object type

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
555c1193071e97926fa67c038244c047?d=identicon&s=25 Phy Prabab (Guest)
on 2007-02-20 06:35
(Received via mailing list)
Got it.  thanks!

----- Original Message ----
From: Harold Hausman <>
To: ruby-talk ML <>
Sent: Monday, February 19, 2007 9:09:47 PM
Subject: Re: How to find out object type

On 2/20/07, Phy Prabab <> wrote:
> irb(main):006:0>
> I was hoping to be create an array from the numb stored as "o", but this must be wrong,
> because trying to get the class of the object does not work.  Any help?

irb(main):001:0> o = 42
=> 42
irb(main):002:0> the_o_array = [o]
=> [42]
irb(main):003:0> the_o_array.class
=> Array

31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 Austin Ziegler (austin)
on 2007-02-20 14:06
(Received via mailing list)
On 2/20/07, Phy Prabab <> wrote:
> Got it.  thanks!

I'm not sure you do.

> On 2/20/07, Phy Prabab <> wrote:
> > ah, thats better.  So now for the real nubie question, I am lost as to why this does 
not work:
> >
> > irb(main):001:0> o = 123
> > => 123
> > irb(main):002:0> #{o} =

This won't work. The "#{o}" notation only works in string
interpolation. Outside of strings (and string-like constructors like
Regexp literal notations), # acts as a comment. So both of your
examples were no-ops. Your understanding of Ruby's syntax and
philosophy bit you here.

I think that you need to look around for comments about "duck typing";
I'd look very closely at some of the tutorials available on the web
before you go much further.

This topic is locked and can not be replied to.