From: Chris Carter Date: 2007-06-13T07:51:59+09:00 Subject: Re: Extending Symbol with #to_str effects Struct.new On 6/12/07, Trans wrote: > Not arguing either way a s to whether this makes sense or not (it's > had it's lengthy discussions before). > > > class Symbol > > def to_str > > String(self) > > end > > end > > But it does cause this strangeness: > > > Struct.new(:x) > NameError: identifier x needs to be constant > from (irb):6:in `new' > from (irb):6 > from :0 > > Is it really THAT unreasonable an extension? I wonder what else it > would effect, and why. I don't really even understand the error > message, but one gets the same result with: > > > Struct.new('x') > NameError: identifier x needs to be constant > from (irb):1:in `new' > from (irb):1 > from :0 > > That in itself seems silly. > > T. > > > This is because if Struct gets a String or a "string like object (responds_to? :to_str)" it uses an alternate behavior where the first argument, if a proper Constant name in a string, is defined to be the Struct class generated under the Struct:: namespace. -- Chris Carter concentrationstudios.com brynmawrcs.com