2 categories::Common methods
3 summary::test if object fulfils a constraint
5 Implemented by: link::Classes/Object::, link::Classes/Collection::, link::Classes/Nil::, link::Classes/Function::
7 method:: matchItem(item)
9 matchItem(item) may be passed to different objects that behave as constraints. More Objects may be conceived to implement matchItem to extend the interface.
11 See also: link::Classes/Dictionary#-matchAt::.
13 section:: Object-matchItem
14 Test if strong::item:: is identical to strong::object::.
16 a = [1, 2, 3, "wort", "1", [pi, 2pi]];
17 a.any { |x| x.matchItem(3) }; // true
18 a.any { |x| x.matchItem(5) }; // false
19 a.any { |x| x.matchItem("wort") }; // false, because "wort" == "wort" but not identical.
22 section::Collection-matchItem
23 Test if strong::item:: is included in strong::collection::.
25 a = [1, 2, 3, "wort", "1", [pi, 2pi]];
26 a.any { |x| x.matchItem(pi) }; // true
29 section::Nil-matchItem
30 returns true (link::Classes/Nil:: serves as a "joker", a stand-in for anything).
32 a = [nil, 1, 2, 3, "wort", "1", [pi, 2pi]];
33 a.any { |x| x.matchItem(10000.rand) }; // true always
36 section::Function-matchItem
37 Test strong::item:: by passing it to a function which should return a link::Classes/Boolean::.
39 a = [10, 20, 30, { |item| item.isPrime }];
40 a.any { |x| x.matchItem(3) }; // true
41 a.any { |x| x.matchItem(4) }; // false
42 a.any { |x| x.matchItem(10) }; // true