HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-3.0.2/spec/ruby/core/proc/shared/call_arguments.rb
describe :proc_call_block_args, shared: true do
  it "can receive block arguments" do
    Proc.new {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
    -> &b { b.send(@method)}.send(@method) {1 + 1}.should == 2
    proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
  end

  it "yields to the block given at declaration and not to the block argument" do
    proc_creator = Object.new
    def proc_creator.create
      Proc.new do |&b|
        yield
      end
    end
    a_proc = proc_creator.create { 7 }
    a_proc.send(@method) { 3 }.should == 7
  end

  it "can call its block argument declared with a block argument" do
    proc_creator = Object.new
    def proc_creator.create(method_name)
      Proc.new do |&b|
        yield + b.send(method_name)
      end
    end
    a_proc = proc_creator.create(@method) { 7 }
    a_proc.call { 3 }.should == 10
  end
end