Ruy is a lightweight rules evaluator
Fork me on GitHub

Why Ruy

Ruy defines an easy-to-learn language which allows users to declare context-driven conditional expressions. For example, it may be used in determining the number of miles earned by Alice while shopping during Black Friday for a total of $400 via credit card, resulting in Alice being eligible for 1,000 miles.


Using

  • discount_day.rb
gifter = Ruy::Rule.new

gifter.set :name, 'Unforgettable Fridays'

gifter.eq :friday, :day_of_week

gifter.outcome 7 do
  greater_than_or_equal 100, :amount
end

gifter.fallback 0



gifter.call(day_of_week: :friday, amount: 256)
# => 7

gifter.call(day_of_week: :monday, amount: 124)
# => 0