From: Robert Klemme Date: 2011-03-17T17:07:47+09:00 Subject: Re: NoMethodError#message takes very long On Wed, Mar 16, 2011 at 10:28 PM, Adiel Mittmann wrote: > Hi, I discovered what's causing the problem. > > Ruby's function name_err_mesg_to_str (file error.c, line 929, SVN snapshot), > which produces the dreaded message, proceeds as follows: > > 1. It converts the object that does not possess the method in question to a > string, by calling #inspect; > > 2. If it doesn't like that string (i.e., if it's nil or is bigger than 65 > characters), then it creates a simpler representation and use it instead. > > In other words, if you happen to call a method on an object that doesn't define > to_s but that does contain a lot of data, then calling an undefined method and > trying to print the resulting exception's message will take a long time because > all the data in the object will have to be converted to a string -- just to be > discarded. > > Maybe in a case like this the message should always return the simpler > representation of the object instead of calling to_s? I'd rather provide a custom #inspect method for objects which may contain potentially large volumes of data. Nobody can read that anyway when printed on console or somewhere else. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/