Issue #15265 has been updated by duerst (Martin Drst).


mame (Yusuke Endoh) wrote:
> Indeed, it looks a very subjective view of the author (Dave Thomas).  Though, I can't understand its subtlety because I'm not a native speaker.
> 
> It might have been just a joke, but anyway, more or less, he wanted to say that "do not use this method easily", I guess.  This kind of meta programming feature can shoot yourself in the foot.  So, I think that rephrasing is better than just dropping.

I agree with Yusuke here. The wording is slightly odd for documentation, so I'd reword along the following lines:

"Sets the instance variable named by symbol to the given object. This may circumvent the the encapsulation intended by the author of the class, so it should be used with care."

----------------------------------------
Misc #15265: Documentation for `Object#instance_variable_set` is inaccurate and pejorative
https://bugs.ruby-lang.org/issues/15265#change-74654

* Author: CaryInVictoria (Cary Swoveland)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
The v2.5.1 documentation for this method states, in part, "Sets the instance variable named by symbol to the given object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation." The phrase beginning, "thereby..." is not necessarily true and seems to mock the fact that the method has been provided to us for its use. Suppose, for example, that the author has provided getters and setters for *all* of an object's instance variables, so there is no encapsulation issue. There still may be situations where this method (and `Object#instance_variable_get`) could be used to advantage. One is where we want to perform certain operations on all instances variables. Where it is possible to write, `<instance>.instance_variables.each { |v| f(v) }`, this has several advantages over manipulating the instance variables individually: it requires less code, debugging and testing is simpler, there is less chance of introducing a bug; and adding, removing or renaming instance variables may not require `f(v)` to be changed.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>