module Rulz class Condition attr_accessor :name, :proc def initialize(name, klass, proc) @name = name @proc = proc klass.instance_exec self do |condition| @rulz_conditions ||= [] @rulz_conditions << condition end end def self.find(klass, name) result = klass.instance_eval { @rulz_conditions }.find {|c| c.name == name } raise ArgumentError, "Condition '#{name}' does not exist" unless result result end end end