Class: Mayak::Predicates::Rule
- Inherits:
-
Object
- Object
- Mayak::Predicates::Rule
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Defined in:
- lib/mayak/predicates/rule.rb
Constant Summary collapse
- A =
type_member
Instance Attribute Summary collapse
-
#fn ⇒ Object
readonly
Returns the value of attribute fn.
Instance Method Summary collapse
- #any(another) ⇒ Object (also: #|)
- #both(another) ⇒ Object (also: #&)
- #call(object) ⇒ Object
- #from(function) ⇒ Object
-
#initialize(&blk) ⇒ Rule
constructor
A new instance of Rule.
- #negate ⇒ Object (also: #!)
- #presence ⇒ Object
Constructor Details
Instance Attribute Details
#fn ⇒ Object (readonly)
Returns the value of attribute fn.
14 15 16 |
# File 'lib/mayak/predicates/rule.rb', line 14 def fn @fn end |
Instance Method Details
#any(another) ⇒ Object Also known as: |
35 36 37 38 39 |
# File 'lib/mayak/predicates/rule.rb', line 35 def any(another) Mayak::Predicates::Rule[A].new do |object| fn.call(object) || another.call(object) end end |
#both(another) ⇒ Object Also known as: &
27 28 29 30 31 |
# File 'lib/mayak/predicates/rule.rb', line 27 def both(another) Mayak::Predicates::Rule[A].new do |object| fn.call(object) && another.call(object) end end |
#call(object) ⇒ Object
22 23 24 |
# File 'lib/mayak/predicates/rule.rb', line 22 def call(object) fn.call(object) end |
#from(function) ⇒ Object
55 56 57 58 59 |
# File 'lib/mayak/predicates/rule.rb', line 55 def from(function) Mayak::Predicates::Rule.new do |object| fn.call(function.call(object)) end end |
#negate ⇒ Object Also known as: !
43 44 45 46 47 |
# File 'lib/mayak/predicates/rule.rb', line 43 def negate Mayak::Predicates::Rule[A].new do |object| !fn.call(object) end end |
#presence ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mayak/predicates/rule.rb', line 62 def presence Mayak::Predicates::Rule[T.nilable(A)].new do |object| case object when nil false else fn.call(object) end end end |