Re: encapsulation issue
by Ralph Shnelvar other posts by this author
Nov 6 2009 6:44AM messages near this date
Re: encapsulation issue
|
Re: encapsulation issue
James,
It appears, also, that changing @dependencies to a constant also does
not help. Strange.
Ralph
Friday, November 6, 2009, 6:50:30 AM, you wrote:
JF> Hi,
JF> Is there any way of providing read only access to an array? (problem shown by code below
).
JF> class A
JF> def initialize
JF> @dependencies = []
JF> end
JF> # intended to be read only access
JF> def dependencies
JF> @dependencies
JF> end
JF> def addDependency(d)
JF> @dependencies << d
JF> puts "adding #{d}"
JF> end
JF> end
JF> a = A.new
JF> a.addDependency("foo")
JF> a.dependencies << "bar" # encapsulation subverted
JF> puts a.dependencies # foo and bar both in array
JF> Any suggestions appreciated,
JF> James
--
Best regards,
Ralph mailto:ralphs@dos32.com
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
|