Re:Java 9 features announced
by muchabi on Monday August 18, 2014 @04:02PM
(#8194329)
To add another example to the list, Ruby lets you list which attributes can be read/written and which ones can only be read on top. Something like.
[ Parent
| on HN ]
It's worth noting that in Ruby the difference between attr_reader and attr_writer is not the same as read only and write only. You can write to something set with attr_reader. All attr_writer does is allow complete reassignment of that particular instance variable.
This is pretty trivial so bear with me... If you have something that looks like this...
class Person
attr_reader :children
def initialize
@children = []
end
end
You can then do this... x = Person.new
x << "Bobby"
You will have then altered the value of @children without completely reassigning it.