Class: Fathom::Simulation
- Inherits:
-
Object
- Object
- Fathom::Simulation
- Defined in:
- lib/fathom/simulation.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
Class Method Summary collapse
-
.define_callback_accessor(callback, obj) ⇒ Object
Expects a symbol for the callback to define on the simulation.
Instance Method Summary collapse
- #callbacks ⇒ Object
-
#initialize(*agents) ⇒ Simulation
constructor
A new instance of Simulation.
Constructor Details
#initialize(*agents) ⇒ Simulation
Returns a new instance of Simulation.
28 29 30 31 |
# File 'lib/fathom/simulation.rb', line 28 def initialize(*agents) @agents = agents assert_callbacks end |
Instance Attribute Details
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
26 27 28 |
# File 'lib/fathom/simulation.rb', line 26 def agents @agents end |
Class Method Details
.define_callback_accessor(callback, obj) ⇒ Object
Expects a symbol for the callback to define on the simulation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fathom/simulation.rb', line 7 def define_callback_accessor(callback, obj) call_method = callback.to_s.scan(/^on_(\w+)/).flatten.compact.first raise ArgumentError, "Callback doesn't appear to be a callback: #{callback}" unless call_method return true if self.respond_to?(call_method) define_method(call_method) do callbacks[callback].each do |agent| agent.send(callback, obj) end end agent_lookup_method = "agents_using_#{call_method}".to_sym return true if self.respond_to?(agent_lookup_method) define_method(agent_lookup_method) do callbacks[callback] end end |
Instance Method Details
#callbacks ⇒ Object
33 34 35 |
# File 'lib/fathom/simulation.rb', line 33 def callbacks @callbacks ||= {} end |