Ruler is a project mainly written in Ruby, based on the MIT license.
Ruby DSL for simplifying conditional logic
= ruler
Ruler is a simple module providing a DSL that helps with defining facts and rules. While ruler is not a prolog or a full-fledged production rule system, it might become one someday.
== How To Use It
You use it whenever you would have a long set of nested if/else blocks or other kinds of conditional logic. require 'rubygems' require 'ruler' class TeaDrinker include Ruler attr_accessor :tea
def make_iced_tea
puts "Making tea"
end
def drink_iced_tea
puts "Ahhhhhhh"
end
def thirsty?
true
end
def tea_check outside_temp
ruleset do
fact :it_is_hot, outside_temp >= 100.0
fact :iced_tea_made, true
fact :no_iced_tea, notf(:iced_tea_made)
fact :am_thirsty, self.thirsty?
rule [:it_is_hot, :am_thirsty, :no_iced_tea] do
make_iced_tea
end
rule [:it_is_hot, :am_thirsty, :iced_tea_made] do
drink_iced_tea
end
end
end
end
== Contributing to ruler
== Copyright
Copyright (c) 2011 Joshua Smith. See LICENSE.txt for further details.