Class: J8::Predicate
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Common
callable_from_proc, from_callable, from_callable_class, initialize, lambda?, make_lambda, raise_unless_lambda
Class Method Details
.equal?(target) ⇒ Boolean
7
8
9
|
# File 'lib/j8/predicate.rb', line 7
def self.equal?(target)
J8::Predicate.new(->(o) { o == target })
end
|
Instance Method Details
#and(other = nil, &block) ⇒ Object
19
20
21
22
23
|
# File 'lib/j8/predicate.rb', line 19
def and(other = nil, &block)
callable = from_callable(other, block)
J8::Predicate.new(->(o) { test(o) && callable.test(o) })
end
|
15
16
17
|
# File 'lib/j8/predicate.rb', line 15
def negate
J8::Predicate.new(->(o) { !test(o) })
end
|
#or(other = nil, &block) ⇒ Object
25
26
27
28
29
|
# File 'lib/j8/predicate.rb', line 25
def or(other = nil, &block)
callable = from_callable(other, block)
J8::Predicate.new(->(o) { test(o) || callable.test(o) })
end
|
11
12
13
|
# File 'lib/j8/predicate.rb', line 11
def test(o)
@callable.call(o)
end
|