Browse Source

Implement

master
Dylan Baker 5 years ago
parent
commit
e2f0da5eda
1 changed files with 9 additions and 0 deletions
  1. 9
    0
      lib/chervil/core.rb

+ 9
- 0
lib/chervil/core.rb View File

@@ -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

Loading…
Cancel
Save