Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

basvanwesting's Profile

GitHub User: basvanwesting

Comments by

Avatar

I have had the same issue with equality. I ended up letting Struct solve the equality issues for me. This preserves equality for usage with arrays, hash (keys), sets etc..

The example below decorates ServiceType with start_date & end_date from another model:

ruby
ServiceTypeWithDates = Struct.new(:service_type) do

  attr_accessor :thing_with_start_and_end_date

  def initialize(service_type, thing_with_start_and_end_date)
    super(service_type)
    self.thing_with_start_and_end_date = thing_with_start_and_end_date
  end

  delegate :start_date, :end_date, :to => :thing_with_start_and_end_date
  delegate *ServiceType.column_names, :to => :service_type

end