
# See  http://electricsheep.blogspot.com/2007_04_01_archive.html

require 'Properties'

class CruiseShip
  extend Properties
  
  # property :direction
  # property :direction, includes?('north', 'south', 'east', 'west')
  # property(:speed) { |v| v >= 0 && v <= 300 }
  property(:direction, includes?('north', 'south', 'east', 'west')) { |v| v == 'thataway' }
  property :speed, is?(0..300)
end

h = CruiseShip.new

h.add_direction_listener(lambda { |x| puts "Oy... someone changed the direction to #{x}"})
h.direction = "north"

h.add_speed_listener(lambda { |x| puts "Oy... someone changed the speed to #{x}"})
h.add_speed_listener(lambda { |x| puts "Yo, dude... someone changed the speed to #{x}"})

h.speed = 200
h.speed = 300

h.speed = 301
h.speed = -1

h.direction = "south"

puts h.direction
puts h.speed

h.remove_speed_listener(1)

h.speed = 200
h.speed = 350

# h.direction = "thataway"
h.direction = "whatever"

puts h.direction
puts h.speed

# pp h.methods
