Class: Click::Clicker

Inherits:
Object
  • Object
show all
Defined in:
lib/click/clicker.rb

Instance Method Summary collapse

Instance Method Details

#add_observer(observer) ⇒ Object



33
34
35
# File 'lib/click/clicker.rb', line 33

def add_observer(observer)
  observers << observer
end

#click!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/click/clicker.rb', line 3

def click!
  observers.each { |o| o.before_click(self) }

  ObjectSpace.garbage_collect

  @state = Hash.new(0)
  ObjectSpace.each_object do |object|
    begin
      klass = object.class
      next unless klass.is_a?(Class)
    rescue NoMethodError
      next
    end

    @state[klass] += 1
  end

  @state[Symbol] = Symbol.all_symbols.count

  observers.each { |o| o.after_click(self) }
end

#instance_count(klass) ⇒ Object



29
30
31
# File 'lib/click/clicker.rb', line 29

def instance_count(klass)
  @state.fetch(klass, 0)
end

#object_countsObject



25
26
27
# File 'lib/click/clicker.rb', line 25

def object_counts
  @state.dup
end