[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Funny doc for setter

John Joyce

5/5/2007 4:56:00 PM

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.


3 Answers

Robert Dober

5/5/2007 8:50:00 PM

0

On 5/5/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:
> Is it just me or is this funny?

I see the same subtle humor here :)

Robert

Ken Bloom

5/9/2007 12:29:00 AM

0

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

--Ken

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Rick DeNatale

5/9/2007 8:43:00 PM

0

On 5/8/07, Ken Bloom <kbloom@gmail.com> 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.denh...