Skip to content

Comment on Ruby mistakesparent

Comments

It's a special parser case. The reason is that defined? may be followed by an uninitialized constant:

  jruby-1.6.8 :089 > defined? Foo::Bar
   => nil 
  jruby-1.6.8 :090 > Foo::Bar
  NameError: uninitialized constant Foo::Bar
You don't want the argument to be evaluated because that could raise a NameError. It's actually an operator.

Thanks for the clarification. I was recently surprised by the return value when:

z = x.y

z == x.y # => true

defined?(z) == defined?(x.y) # => false

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.