Easily build a great vocabulary without studying! Now on the App Store!
Click here for more info about the app
I just wrote and released my first Ruby Gem, Hashed Attributes https://rubygems.org/gems/hashed_attributes. It is a very simple ActiveRecord extension for saving variables through a serialized hash. The Gem will let you declare getter and setter methods that use a hash to store assigned data. For instance, instead of doing something like
you can do
@user.preferences[:favorite_color] = 'orange'
The value for favorite color will be kept in a serialized hash.
@user.favorite_color = 'orange'
Setup in the model is very straight forward. The first argument is the column name you want to use followed by a list of methods used as keys on the hash.
class Person < ActiveRecord::Base hashed_attributes :preferences, :favorite_color, :theme, :plan # etc... end
ActiveRecord is required to use this gem. Additionally, you need to add a column in your database.
create_table :people do |t| t.text :preferences end
Or place in your Rails Gemfile
gem install hashed_attributes
Releasing this gem was a lot of fun and I'm looking forward to writing more gems!