Class: Click::Clicker
- Inherits:
-
Object
- Object
- Click::Clicker
- Defined in:
- lib/click/clicker.rb
Instance Attribute Summary collapse
-
#session_name ⇒ Object
readonly
Returns the value of attribute session_name.
Instance Method Summary collapse
- #add_observer(observer) ⇒ Object
- #click! ⇒ Object
-
#initialize(session_name) ⇒ Clicker
constructor
A new instance of Clicker.
- #instance_count(klass) ⇒ Object
- #object_counts ⇒ Object
Constructor Details
#initialize(session_name) ⇒ Clicker
Returns a new instance of Clicker.
7 8 9 |
# File 'lib/click/clicker.rb', line 7 def initialize(session_name) @session_name = session_name end |
Instance Attribute Details
#session_name ⇒ Object (readonly)
Returns the value of attribute session_name.
5 6 7 |
# File 'lib/click/clicker.rb', line 5 def session_name @session_name end |
Instance Method Details
#add_observer(observer) ⇒ Object
41 42 43 44 |
# File 'lib/click/clicker.rb', line 41 def add_observer(observer) observers << observer observer.on_add(self) end |
#click! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/click/clicker.rb', line 11 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 klass = Click::Indeterminable unless klass.is_a?(Class) rescue NoMethodError klass = Click::Indeterminable end @state[klass] += 1 end @state[Symbol] = Symbol.all_symbols.count observers.each { |o| o.after_click(self) } end |
#instance_count(klass) ⇒ Object
37 38 39 |
# File 'lib/click/clicker.rb', line 37 def instance_count(klass) @state.fetch(klass, 0) end |
#object_counts ⇒ Object
33 34 35 |
# File 'lib/click/clicker.rb', line 33 def object_counts @state.dup end |