Closed djberg96 closed 4 years ago
@kbrock simplified as per your recommendation, thanks! Also, added specs.
@zilkey Ok, should be good to go.
Is there a way to define a spec for this?
It would probably be your test.rb
with minimal changes
@kbrock I added a spec (though note that I'm also trying to get the specs updated to rspec3 in a separate PR).
For future readers:
Using ruby private
for a getter/setter will hide an attribute from other classes in the way desired.
Thanks @djberg96 for working this one through
it "honors the private option" do
Country.data = [{:name => "US", :secret => "xxx"}, {:name => "Canada", :secret => "yyy"}]
class Country
private
def secret ; self[:secret] ; end
end
Country.should_not respond_to(:secret)
Country.first.send(:secret).should eq("xxx")
end
@djberg96 I think the already_defined? is much better than the existing solution. think that would be nice in a pr you're probably tired of this feature, so I can cherry-pick those into a separate pr
@kbrock I will leave it to you to pick what you want out of that PR. :)
The idea here is that
data
may be coming from an external source, and you don't want it all to be publicly accessible, but you still want it to be accessible internally for other methods. So, for example, you would have something like this:WIP for now until I can figure it a proper implementation, and also see if such a thing is of interest.Followup to https://github.com/zilkey/active_hash/issues/199