Class: Rulz::Rule
- Inherits:
-
Object
- Object
- Rulz::Rule
- Defined in:
- lib/rulz/rule.rb
Instance Attribute Summary collapse
-
#proc ⇒ Object
Returns the value of attribute proc.
Class Method Summary collapse
Instance Method Summary collapse
- #apply!(receiver) ⇒ Object
-
#initialize(klass, proc) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(klass, proc) ⇒ Rule
Returns a new instance of Rule.
5 6 7 8 9 10 11 |
# File 'lib/rulz/rule.rb', line 5 def initialize(klass, proc) @proc = proc klass.instance_exec self do |rule| @rulz_rules ||= [] @rulz_rules << rule end end |
Instance Attribute Details
#proc ⇒ Object
Returns the value of attribute proc.
3 4 5 |
# File 'lib/rulz/rule.rb', line 3 def proc @proc end |
Class Method Details
.rules(klass) ⇒ Object
17 18 19 |
# File 'lib/rulz/rule.rb', line 17 def self.rules(klass) klass.instance_eval { @rulz_rules } end |
Instance Method Details
#apply!(receiver) ⇒ Object
13 14 15 |
# File 'lib/rulz/rule.rb', line 13 def apply!(receiver) Rulz::Evaluator::Rule.new(receiver, @proc).evaluate end |