Skip to content

Commit

Permalink
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions spec/ruby/core/proc/parameters_spec.rb
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@
proc {|x| }.parameters.first.first.should == :opt
end

it "regards optional keyword parameters in procs as optional" do
proc {|x: :y| }.parameters.first.first.should == :key
end

it "regards parameters with default values as optional" do
lambda {|x=1| }.parameters.first.first.should == :opt
proc {|x=1| }.parameters.first.first.should == :opt
@@ -34,13 +38,24 @@
lambda {|x| }.parameters.first.first.should == :req
end

it "regards keyword parameters in lambdas as required" do
lambda {|x:| }.parameters.first.first.should == :keyreq
end

it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do
lambda {|*x| }.parameters.first.first.should == :rest
lambda {|x,*y| }.parameters.last.first.should == :rest
proc {|*x| }.parameters.first.first.should == :rest
proc {|x,*y| }.parameters.last.first.should == :rest
end

it "sets the first element of each sub-Array to :keyrest for parameters prefixed with double asterisks" do
lambda {|**x| }.parameters.first.first.should == :keyrest
lambda {|x,**y| }.parameters.last.first.should == :keyrest
proc {|**x| }.parameters.first.first.should == :keyrest
proc {|x,**y| }.parameters.last.first.should == :keyrest
end

it "sets the first element of each sub-Array to :block for parameters prefixed with ampersands" do
lambda {|&x| }.parameters.first.first.should == :block
lambda {|x,&y| }.parameters.last.first.should == :block

0 comments on commit e60d0dd

Please sign in to comment.