Funny doc for setter

J

John Joyce

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.
 
K

Ken Bloom

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
 
R

Rick DeNatale

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,241
Messages
2,571,223
Members
47,860
Latest member
LoganF4991

Latest Threads

Top