encapsulation issue
by James French other posts by this author
Nov 6 2009 5:53AM messages near this date
Re: [ANN] Ruby-Tk LIbraries Runtime Library 3.0 and Gestalt Items
|
Re: encapsulation issue
Hi,
Is there any way of providing read only access to an array? (problem shown by code below).
class A
def initialize
@dependencies = []
end
# intended to be read only access
def dependencies
@dependencies
end
def addDependency(d)
@dependencies << d
puts "adding #{d}"
end
end
a = A.new
a.addDependency("foo")
a.dependencies << "bar" # encapsulation subverted
puts a.dependencies # foo and bar both in array
Any suggestions appreciated,
James
Thread:
James French
Josh Cheek
James French
Ralph Shnelvar
Gavin Sinclair
James French
Seebs
Aldric Giacomoni
David A. Black
James French
David A. Black
Tom Stuart
James French
|