From: Rick DeNatale Date: 2007-05-10T05:43:17+09:00 Subject: Re: Funny doc for setter On 5/8/07, Ken Bloom wrote: > On Sun, 06 May 2007 01:56:18 +0900, John Joyce wrote: > > > Is it just me or is this funny? > > > > > > ------------------------------------------- Object#instance_variable_set > > obj.instance_variable_set(symbol, obj) => obj > > ------------------------------------------------------------------------ > > Sets the instance variable names by _symbol_ to _object_, thereby > > frustrating the efforts of the class's author to attempt to > > provide > > proper encapsulation. The variable did not have to exist prior to > > this call. > > Yeah, but it doesn't expose anything that didn't already exist in Ruby. > If the function didn't exist, you could write it yourself: > > class Object > def instance_variable_set symbol, obj > eval "@#{symbol}=obj" > end > end Ahh, but it's a subtle reminder that even if something is possible one shouldn't always do it, at least without thought to the consequences. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/