On Wed, Sep 22, 2010 at 5:35 PM, Jarmo Pertman <jarmo.p / gmail.com> wrote: > Hello! > > I've just landed upon a very interesting landmine by using defined? > > Consider the following code: > > # a.rb > module A > ¨ÂõôïìïáºÂ¢â®ò⢠> end > > defined?(A::B::C) > p A::B > p A::B.new.one > p A::B.new.two > > > # b.rb > module A > ¨Âìáóó > ¨Âõô¢ìïáäéîç> ¨Âåæ ïîå» ±» åî> > ¨Âáéóå ¢îïîïîï¡> > ¨Âåæ ô÷ï» ²» åî> ¨Âîä > end > > So, when running a.rb what would you expect? > > I would expect defined? line to raise an RuntimeError,... Why? defined? is there to check WITHOUT raising an runtime error ruby-1.8.7-p302 > defined? Blatz => nil ruby-1.8.7-p302 > defined? A::B::C => nil ruby-1.8.7-p302 > defined? Object => "constant" And it's the same for 1.9.2 ruby-1.9.2-p0 > defined? Blatz => nil ruby-1.9.2-p0 > defined? A::B::C => nil ruby-1.9.2-p0 > defined? Object => "constant" -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale