--_000_950618E0D00138499BE7CC487EBF646D65F38CD3E1WOODCHUCKNMlo_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
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
--_000_950618E0D00138499BE7CC487EBF646D65F38CD3E1WOODCHUCKNMlo_--