|
@@ -32,6 +32,14 @@ module Chervil
|
32
|
32
|
end
|
33
|
33
|
end
|
34
|
34
|
|
|
35
|
+ def self.arity_check(args, expected_count)
|
|
36
|
+ if args.size != expected_count
|
|
37
|
+ ::Chervil::Error.new("Expected #{expected_count} arguments but received #{args.size}")
|
|
38
|
+ else
|
|
39
|
+ nil
|
|
40
|
+ end
|
|
41
|
+ end
|
|
42
|
+
|
35
|
43
|
CORE = {
|
36
|
44
|
"+" => Proc.new { |args| type_check(args, Float) || args.inject(:+) },
|
37
|
45
|
"-" => Proc.new { |args| type_check(args, Float) || args.inject(:-) },
|
|
@@ -44,6 +52,7 @@ module Chervil
|
44
|
52
|
">=" => Proc.new { |args| type_check(args, Float) || compare_pairs(args, :>=) },
|
45
|
53
|
"and" => Proc.new { |args| !(args.include?(false)) },
|
46
|
54
|
"or" => Proc.new { |args| args.any? { |arg| !!arg == true } },
|
|
55
|
+ "not" => Proc.new { |args| arity_check(args, 1) || args.first == false ? true : false },
|
47
|
56
|
}
|
48
|
57
|
end
|
49
|
58
|
end
|