Introducing acts_as_comparable 21 Apr 2007
Mark VanHolstyn and Zach Dennis kick out another ActiveRecord plugin. The previous plugin “ActiveRecord::Extensions”: now has a smaller, helpful cousin. This plugin has been in use for over a year but not released until tonight!

“acts_as_comparable” is plugin for ActiveRecord which allows you to easily compare and determine the differences between two ActiveRecord models.

class Person 
  acts_as_comparable :only=>\[:first_name, :last_name\]

joe = :first_name=>"Joe", :last_name=>"Smith"
joseph = :first_name => "Joseph", :last_name=>"Smith"

joe.same?( joseph ) # => false
joe.different?( joseph ) # => true

joe.differences( joseph ) # => {:first_name=>\["Joe", "Joseph"\]}

The usage in the above example shows the only option, but this also works with no options, the except option and also the attrsmap_ option. See it’s ruby doc for more information.

Installing as a RubyGem

gem install -r acts_as_comparable

Installing as a Plugin

Installing from a version

script/plugin install

blog comments powered by Disqus