Skip to content

Instantly share code, notes, and snippets.

@petrokoriakin
Created July 10, 2015 23:26
Show Gist options
  • Save petrokoriakin/16dba770aecf243aa1f1 to your computer and use it in GitHub Desktop.
Save petrokoriakin/16dba770aecf243aa1f1 to your computer and use it in GitHub Desktop.
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