3 ms·
Why are private properties so sorely needed? Ruby is an OOP language, and gets along just fine without it.
by simplify 9y ago
Why are private properties so sorely needed? Ruby is an OOP language, and gets along just fine without it.
- dwb 9y agoYou can declare visibility in Ruby: https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes#Declaring_Visibility https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classe... It can usually (always?) be gotten around though.
- simplify 9y agoRight. You can say something's "private", but there's always a way to access it. As far as I'm aware, this has never been an actual problem, and in fact has been useful since you can "patch" a library if you really need to.
- frou_dh 9y agoAdmittedly I have barely used Ruby, but isn't the fact that those "attr_reader"s have to be declared explicitly an indication that the fields are private by default?
- simplify 9y agoattr_reader :my_prop is just a shorthand way of creating a convenience method that returns the internal value of @my_prop. But in any case, there is always a way to access a Ruby object's internal instance values. See my other comment in this thread.