Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created March 3, 2011 12:51
Show Gist options
  • Save JakubOboza/852704 to your computer and use it in GitHub Desktop.
Save JakubOboza/852704 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'transitions'
# show me the caller name
module Wombatize
def method_name
caller[0][/`([^']*)'/, 1]
end
end
class Relationship
include Transitions
include Wombatize
def strictly_for_fun?
puts method_name
end
def drunk?
puts method_name
end
def willing_to_give_up_manhood?
puts method_name
end
def make_happy
puts method_name
end
def make_depressed
puts method_name
end
def make_very_happy
puts method_name
end
def never_speak_again
puts method_name
end
def give_up_intimacy
puts method_name
end
def buy_exotic_car_and_wear_a_combover
puts method_name
end
state_machine do
state :dating, :enter => :make_happy, :exit => :make_depressed
state :intimate, :enter => :make_very_happy, :exit => :never_speak_again
state :married, :enter => :give_up_intimacy, :exit => :buy_exotic_car_and_wear_a_combover
event :get_intimate do
transitions :to => :intimate, :from => [:dating], :guard => :drunk?
end
event :get_married do
transitions :to => :married, :from => [:dating, :intimate], :guard => lambda {|relation| puts "Willing to giveup manhood?"}
end
end
end
r = Relationship.new
r.get_married
r.get_married
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment