Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created September 10, 2013 06:29
Show Gist options
  • Save elskwid/6505679 to your computer and use it in GitHub Desktop.
Save elskwid/6505679 to your computer and use it in GitHub Desktop.
Potential fix for Virtus::ValueObjects inheritance issue
require "virtus"
class Teacher
include Virtus::ValueObject
attribute :id, String
def self.inherited(descendant)
super
descendant.define_singleton_method(:equalizer) do
@equalizer ||=
begin
equalizer = Equalizer.new(name || inspect)
include equalizer
attribute_set.each do |attribute|
equalizer << attribute.name
end
equalizer
end
end
end # self.inherited
end
class TeachingAssistant < Teacher
attribute :major, String
end
ta1 = TeachingAssistant.new(id: 1)
ta2 = TeachingAssistant.new(id: 2)
puts ta1.inspect
# => #<TeachingAssistant id="1" major=nil>
puts ta1.id
# => 1
puts ta2.inspect
# #<TeachingAssistant id="2" major=nil>
puts ta2.id
# => 2
puts ta1 == ta2
# false
puts ta1.eql? ta2
# false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment