[前][次][番号順一覧][スレッド一覧]

ruby-changes:59353

From: Alan <ko1@a...>
Date: Sat, 21 Dec 2019 23:09:14 +0900 (JST)
Subject: [ruby-changes:59353] e0b336c8ce (master): Add specs for calling into Kernel#lambda with super

https://git.ruby-lang.org/ruby.git/commit/?id=e0b336c8ce

From e0b336c8ce84e1456fc6126ca232289667db3e19 Mon Sep 17 00:00:00 2001
From: Alan Wu <XrXr@u...>
Date: Sun, 14 Jul 2019 23:41:43 -0400
Subject: Add specs for calling into Kernel#lambda with super


diff --git a/spec/ruby/core/kernel/fixtures/classes.rb b/spec/ruby/core/kernel/fixtures/classes.rb
index 2909a62..2f2bbf1 100644
--- a/spec/ruby/core/kernel/fixtures/classes.rb
+++ b/spec/ruby/core/kernel/fixtures/classes.rb
@@ -337,6 +337,28 @@ module KernelSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/fixtures/classes.rb#L337
     end
   end
 
+  module LambdaSpecs
+    module ZSuper
+      def lambda
+        super
+      end
+    end
+
+    class ForwardBlockWithZSuper
+      prepend(ZSuper)
+    end
+
+    module Ampersand
+      def lambda(&block)
+        super(&block)
+      end
+    end
+
+    class SuperAmpersand
+      prepend(Ampersand)
+    end
+  end
+
   class RespondViaMissing
     def respond_to_missing?(method, priv=false)
       case method
diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb
index 4796d65..537ac26 100644
--- a/spec/ruby/core/kernel/lambda_spec.rb
+++ b/spec/ruby/core/kernel/lambda_spec.rb
@@ -31,13 +31,28 @@ describe "Kernel.lambda" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/lambda_spec.rb#L31
     l.lambda?.should be_true
   end
 
-  it "returned the passed Proc if given an existing Proc" do
+  it "returns the passed Proc if given an existing Proc" do
     some_proc = proc {}
     l = lambda(&some_proc)
     l.should equal(some_proc)
     l.lambda?.should be_false
   end
 
+  it "creates a lambda-style Proc when called with zsuper" do
+    l = KernelSpecs::LambdaSpecs::ForwardBlockWithZSuper.new.lambda { 42 }
+    l.lambda?.should be_true
+    l.call.should == 42
+
+    lambda { l.call(:extra) }.should raise_error(ArgumentError)
+  end
+
+  it "returns the passed Proc if given an existing Proc through super" do
+    some_proc = proc { }
+    l = KernelSpecs::LambdaSpecs::SuperAmpersand.new.lambda(&some_proc)
+    l.should equal(some_proc)
+    l.lambda?.should be_false
+  end
+
   it "checks the arity of the call when no args are specified" do
     l = lambda { :called }
     l.call.should == :called
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]