Skip to content

Instantly share code, notes, and snippets.

@adelevie
Created June 7, 2010 21:08
Show Gist options
  • Save adelevie/429200 to your computer and use it in GitHub Desktop.
Save adelevie/429200 to your computer and use it in GitHub Desktop.
require 'rools'
class User
attr_accessor :bankroll, :ready_to_quit
def initialize
@bankroll = bankroll = 1000
@ready_to_quit = ready_to_quit = false
end
def add_bonus!(n)
@bankroll = @bankroll + n
puts "A bonus of $#{n}.00 has been awarded."
end
end
rules = Rools::RuleSet.new do
rule 'Bonus' do
parameter User, :ready_to_quit
condition { user.ready_to_quit == true }
consequence { user.add_bonus!(11) }
end
end
user = User.new
user.ready_to_quit = true
rules.assert user
puts "Current user's bankroll is #{user.bankroll}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment