Class: Ein::Simulator

Inherits:
Object
  • Object
show all
Defined in:
lib/ein/simulator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatter = nil) ⇒ Simulator

Returns a new instance of Simulator.



11
12
13
14
15
16
# File 'lib/ein/simulator.rb', line 11

def initialize(formatter = nil)
  @current_time = Time.now
  @formatter = formatter || Console.new
  @world = World.new
  @running = false
end

Instance Attribute Details

#current_timeObject (readonly)

Returns the value of attribute current_time.



9
10
11
# File 'lib/ein/simulator.rb', line 9

def current_time
  @current_time
end

#formatterObject (readonly)

Returns the value of attribute formatter.



9
10
11
# File 'lib/ein/simulator.rb', line 9

def formatter
  @formatter
end

#worldObject (readonly)

Returns the value of attribute world.



9
10
11
# File 'lib/ein/simulator.rb', line 9

def world
  @world
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ein/simulator.rb', line 31

def running?
  @running
end

#startObject

TODO: should these methods add ! because they modify the simulation ?



19
20
21
22
23
24
# File 'lib/ein/simulator.rb', line 19

def start
  @running = true
  Thread.abort_on_exception = true
  Thread.new { run }
  self
end

#stopObject



26
27
28
29
# File 'lib/ein/simulator.rb', line 26

def stop
  @running = false
  self
end