SuperStruct
Simple extensions to Struct
to make it more compatable with Hash
without the performance penalties of OpenStruct
Installation
Add this line to your application's Gemfile:
gem 'super_struct'
And then execute:
$ bundle
Or install it yourself as:
$ gem install super_struct
Usage
require 'super_struct'
attributes = { name: 'John Doe' }
class Customer < SuperStruct.new(attributes)
def has_attribute?(attribute)
members.include?(attribute.to_sym)
end
end
john_doe = Customer.new(attributes)
=> #<struct Customer name="John Doe">
john_doe.name
=> 'John Doe'
john_doe.has_attribute?(:name)
=> true
john_doe.has_attribute?(:dob)
=> false
Testing
bundle install --path .bundle/bundle
bundle exec rake spec
Contributing
- Fork it ( https://github.com/bramswenson/super_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