Skip to content

Commit

Permalink
Add args forwarding specs
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Feb 12, 2020
1 parent 9d14d3f commit e178432
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions language/args_forwaring_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative '../spec_helper'

ruby_version_is "2.7" do
describe "args forwarding def(...)" do
class F
def target(*args, **kwargs)
[args, kwargs]
end

def target_block(*args, **kwargs)
yield [kwargs, args]
end
end

it "delegates rest and kwargs" do
a = Class.new(F)
a.class_eval(<<-RUBY)
def delegate(...)
target(...)
end
RUBY

a.new.delegate(1, b: 2).should == [[1], {b: 2}]
end

it "delegates block" do
a = Class.new(F)
a.class_eval(<<-RUBY)
def delegate_block(...)
target_block(...)
end
RUBY

a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end
end
end

0 comments on commit e178432

Please sign in to comment.