ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved