Module: Instance

Defined in:
lib/the_blob/instance.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/the_blob/instance.rb', line 3

def self.included(base)
  base.instance_eval do
    def self.underscore
      self.to_s.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
    end

    def self.get_next_id
      @next_id ||= 0
      @next_id += 1
    end

    def self.instance_indices(*ind)
      indices = ind << :id
      attr_accessor *indices
      @instance_indices = indices
    end

    def self.get_instance_indices
      @instance_indices ||= []
    end
  end
end

Instance Method Details

#==(instance_2) ⇒ Object



39
40
41
# File 'lib/the_blob/instance.rb', line 39

def ==(instance_2)
  self.class == instance_2.class && id == instance_2.id
end

#idObject



35
36
37
# File 'lib/the_blob/instance.rb', line 35

def id
  @id
end

#initialize(attrs = {}) ⇒ Object



30
31
32
33
# File 'lib/the_blob/instance.rb', line 30

def initialize(attrs = {})
  @id = self.class.get_next_id
  attrs.each{ |name, value| name.inspect; send("#{name}=", value) }
end