From: shevegen@... Date: 2018-10-28T10:56:45+00:00 Subject: [ruby-core:89604] [Ruby trunk Misc#15265] Documentation for `Object#instance_variable_set` is inaccurate and pejorative Issue #15265 has been updated by shevegen (Robert A. Heiler). Yes I agree. That phrasing is not necessary. There is more than one way to do many things in ruby. A good example is .send() versus .public_send(). I think matz's philosophy is closer towards .send() (which makes more sense to me and I do not use .public_send() myself), but I think it was added to provide those who want "strong" encapsulation with some APIs. Even though I think the distinction between public/private/protected does not make that much sense in ruby to begin with, due to ruby's (awesome) flexibility anyway. Different languages pursue different OOP models. Anyway, I concur with you. I assume that others among the core team may also agree with you (I think, but of course I can not speak for them). The only thing left to do may be to suggest an alternative wording that could be used. What would you suggest? Only dropping the part "thereby frustrating ..." or a complete rewording? ---------------------------------------- Misc #15265: Documentation for `Object#instance_variable_set` is inaccurate and pejorative https://bugs.ruby-lang.org/issues/15265#change-74641 * 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_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 rena ming instance variables may not require `f(v)` to be changed. -- https://bugs.ruby-lang.org/ Unsubscribe: