lib/woyo/world/way.rb in woyo-world-0.0.5 vs lib/woyo/world/way.rb in woyo-world-0.0.6

- old
+ new

@@ -4,16 +4,30 @@ class Way < WorldObject attributes :description, name: lambda { |this| this.id.to_s.capitalize } + group! :passable, :closed, :open # defaults to closed: true + + def world + from ? from.world : nil + end + + def close! + closed! + end + def from @from ||= context end - def world - from ? from.world : nil + def to arg=nil + if arg.nil? + @to + else + self.to = arg + end end def to= arg if arg.instance_of? Symbol case @@ -24,18 +38,19 @@ 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 - def to arg=nil - if arg.nil? - @to - else - self.to = arg - end + attribute :going + + def go + { go: open?, going: self.going } end end end