From: Matt Greer Date: 2007-07-19T07:29:10+09:00 Subject: overriding nil?, curiosity ------=_Part_113167_1001813.1184797754069 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Maybe this is a dumb question, but I'm gonna give it a shot. I was showing my friends how Ruby classes are always open and I did some dumb things like redefine Integer#+ to always return 5, and such. But trying this: NilClass.class_eval do def nil? false end end result in this: irb(main):008:0> nil /opt/local/lib/ruby/1.8/irb/slex.rb:235:in `match_io': undefined method `call' for nil:NilClass (NoMethodError) from /opt/local/lib/ruby/1.8/irb/slex.rb:76:in `match' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:287:in `token' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:263:in `lex' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:234:in `each_top_level_statement' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `loop' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `catch' from /opt/local/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement' from /opt/local/lib/ruby/1.8/irb.rb:146:in `eval_input' from /opt/local/lib/ruby/1.8/irb.rb:70:in `start' from /opt/local/lib/ruby/1.8/irb.rb:69:in `catch' from /opt/local/lib/ruby/1.8/irb.rb:69:in `start' from /opt/local/bin/irb:13 Taking a look at the code and I'm completely lost. Obviously Ruby itself depends on a usable definition of nil? I'm sure it depends on some key methods in String, Array etc to be defined as expected too. So I guess there are some exceptions where ruining a method ruins Ruby itself making it so you never get a chance to ruin your own code :) Like I said, dumb question and just a curiosity, my apologies if this isn't very relevant. ------=_Part_113167_1001813.1184797754069--