class RbRules

Attributes

rules[R]

Public Class Methods

[](key) click to toggle source
# File lib/rbrules.rb, line 18
def self.[](key)
  @rule_sets[key]
end
new() { |self| ... } click to toggle source
# File lib/rbrules.rb, line 22
def initialize(&block)
  @rules = []
  yield(self) if block_given?
end

Public Instance Methods

+(other) click to toggle source
# File lib/rbrules.rb, line 7
def +(other)
  self.class.new do |builder|
    rules.each { |rule| builder.rule(rule) }
    if other.is_a?(self.class)
      other.rules.each { |rule| builder.rule(rule) }
    else
      builder.rule(other)
    end
  end
end
any?(*args) click to toggle source
# File lib/rbrules.rb, line 41
def any?(*args)
  rules.find do |rule|
    rule.call(*args)
  end
end
rule(name_or_rule, &block) click to toggle source
# File lib/rbrules.rb, line 27
def rule(name_or_rule, &block)
  if name_or_rule.respond_to? :call
    rules << name_or_rule
  else
    rules << Rule.new(name_or_rule, block)
  end
end