Created
July 10, 2015 23:26
-
-
Save petrokoriakin/16dba770aecf243aa1f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LibraryItem | |
module Initializer | |
def initialize *args | |
@@group_identifier ||= 0 | |
@identifier = @@group_identifier += 1 | |
super *args | |
end | |
end | |
module ClassMethods | |
def count | |
class_variable_get :@@group_identifier | |
end | |
end | |
def eql? obj | |
self.identifier == obj.identifier | |
end | |
def == obj | |
self.eql? obj | |
end | |
def hash | |
identifier | |
end | |
def self.included(klass) | |
klass.send :extend, ClassMethods | |
klass.send :attr_accessor, :identifier | |
klass.send :prepend, Initializer | |
end | |
end | |
class Bobobo | |
include LibraryItem | |
attr_accessor :attr | |
def initialize attr = 0 | |
@attr = attr | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment