RestrictedStruct
This gem allows to use ruby's Struct, but automatically hides all the attributes as private or protected, which provides higher level of encapsulation.
Installation
Add this line to your application's Gemfile:
gem 'restricted_struct'
And then execute:
$ bundle
Or install it yourself as:
$ gem install restricted_struct
Usage
Instead of doing this:
class Rectangle < Struct.new(:x1, :y1, :x2, :y2)
protected :x1, :x1=, :y1, :y1=, :x2, :x2=, :y2, :y2=
# ...
end
one can do:
class Rectangle < RestrictedStruct.new(:protected, :x1, :y1, :x2, :y2)
# ...
end
Available access levels: :private and :protected.
Contributing
- Fork it ( https://github.com/waterlink/restricted_struct/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request