Class: Woyo::Way
- Inherits:
-
WorldObject
- Object
- WorldObject
- Woyo::Way
- Defined in:
- lib/woyo/world/way.rb
Instance Attribute Summary
Attributes inherited from WorldObject
Instance Method Summary collapse
- #close! ⇒ Object
- #from ⇒ Object
- #initialize_object ⇒ Object
- #to(arg = nil) ⇒ Object
- #to=(arg) ⇒ Object
-
#world ⇒ Object
def go { go: open?, going: self.going } end.
Methods inherited from WorldObject
#attribute_changes, #attribute_clear_changes, #changes, #clear_changes, #initialize, #uid
Methods included from Evaluate
#children, #evaluate, included
Methods included from Attributes
#attribute, #attributes, #changes, #clear_changes, #define_attr, #define_attr!, #define_attr?, #define_attr_default, #define_attr_equals, #define_attr_methods, #dependent_changes, #exclusion, #exclusions, #group, #groups, #is, #is?, #track_changes
Constructor Details
This class inherits a constructor from Woyo::WorldObject
Instance Method Details
#close! ⇒ Object
31 32 33 |
# File 'lib/woyo/world/way.rb', line 31 def close! closed! end |
#from ⇒ Object
35 36 37 |
# File 'lib/woyo/world/way.rb', line 35 def from @from ||= context end |
#initialize_object ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/woyo/world/way.rb', line 7 def initialize_object super attribute :going exclusion :passable, :closed, :open # defaults to closed: true action :go do describe proc { self.context.going } #result proc { self.context.passable } execution do { go: open?, location: open? ? self.to.id : nil } end end end |
#to(arg = nil) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/woyo/world/way.rb', line 39 def to arg=nil if arg.nil? @to else self.to = arg end end |
#to=(arg) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/woyo/world/way.rb', line 47 def to= arg if arg.instance_of? Symbol case when from && arg == from.id @to = from # way loops back to the same location when world && world.locations[arg] @to = world.locations[arg] # destination location already exists in world when world @to = world.location arg # create destination location in world else @to = Location.new arg # create free-standing destination location end self.open! else raise "Symbol required, but #{arg.class} : '#{arg}' given." end end |
#world ⇒ Object
def go
{ go: open?, going: self.going }
end
27 28 29 |
# File 'lib/woyo/world/way.rb', line 27 def world from ? from.world : nil end |