add operator "!~".
authorTomoyuki Sahara <[email protected]>
Fri, 10 Jan 2014 04:41:41 +0000 (10 13:41 +0900)
committerTomoyuki Sahara <[email protected]>
Fri, 10 Jan 2014 04:41:41 +0000 (10 13:41 +0900)
mrblib/kernel.rb
test/t/kernel.rb

index 8ccf3cf..0277a1b 100644 (file)
@@ -43,4 +43,9 @@ module Kernel
       yield
     end
   end
       yield
     end
   end
+
+  # 11.4.4 Step c)
+  def !~(y)
+    !(self =~ y)
+  end
 end
 end
index 0f8fdeb..e7c9c26 100644 (file)
@@ -479,6 +479,27 @@ assert('Kernel#!=') do
   assert_false (str2 != str1)
 end
 
   assert_false (str2 != str1)
 end
 
+# operator "!~" is defined in ISO Ruby 11.4.4. 
+assert('Kernel#!~') do
+  x = "x"
+  def x.=~(other)
+    other == "x"
+  end
+  assert_false x !~ "x"
+  assert_true  x !~ "z"
+
+  y = "y"
+  def y.=~(other)
+    other == "y"
+  end
+  def y.!~(other)
+    other == "not y"
+  end
+  assert_false y !~ "y"
+  assert_false y !~ "z"
+  assert_true  y !~ "not y"
+end
+
 assert('Kernel#respond_to_missing?') do
   class Test4RespondToMissing
     def respond_to_missing?(method_name, include_private = false)
 assert('Kernel#respond_to_missing?') do
   class Test4RespondToMissing
     def respond_to_missing?(method_name, include_private = false)