From: Sigurd Date: 2012-03-07T05:08:50+09:00 Subject: Re: Getting the class of an object. defined? is a INSN RTL, there for it's not "defined" in the ruby script lexical scope. To be clearer - it's Ruby keyword, not a method or whatever. On Mar 6, 2012, at 9:55 PM, Sam Duncan wrote: > On 07/03/12 08:48, Ralph Shnelvar wrote: >> Sam, >> >> Tuesday, March 6, 2012, 12:09:45 PM, you wrote: >> >> SD> On 07/03/12 07:15, Robert Klemme wrote: >>>> You do not want the class but rather the kind of "foo". "local >>>> variable" is not a class. You can do >>>> >>>> irb(main):032:0> class Bogey< Dance >>>> irb(main):033:1> def bar >>>> irb(main):034:2> a=0 >>>> irb(main):035:2> printf "foo -> %p\n", defined?(foo) >>>> irb(main):036:2> printf "a -> %p\n", defined?(a) >>>> irb(main):037:2> printf "none -> %p\n", defined?(none) >>>> irb(main):038:2> end >>>> irb(main):039:1> end >>>> => nil >>>> irb(main):040:0> Bogey.new.bar >>>> foo -> "method" >>>> a -> "local-variable" >>>> none -> nil >>>> => nil >> SD> Great answer. I'm pretty new to Ruby and assumed that defined? returned >> SD> a boolean. That'll learn me for not reading the manual. >> >> SD> Sam >> >> Indeed, it is a great answer. Thanks Robert! >> >> Now where in online documentation can I find where "defined?" is documented? >> >> I see it explained on page 137 of the Pickaxe book but is there more formal documentation online? >> >> Also ... I find it interesting that I get a syntax error when I do >> defined? defined? > > Yeah, that is odd. > > 1.9.2p290 :001 > defined? defined? > SyntaxError: (irb):1: syntax error, unexpected $end > from ~/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
' > 1.9.2p290 :002 > defined?(defined?) > SyntaxError: (irb):2: syntax error, unexpected ')' > from ~/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `
' > 1.9.2p290 :003 > defined? :defined? > => "expression" > > Sam > >