Home > ruler

ruler

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

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2011 Joshua Smith. See LICENSE.txt for further details.