Skip to content

Commit a31755a

Browse files
committedApr 8, 2016
A proc call can use an implicit block. Fixes #3202.
1 parent b8c365d commit a31755a

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
 

Diff for: ‎core/kernel.rb

+23-3
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,29 @@ def private_singleton_methods
725725
end
726726
private :private_singleton_methods
727727

728-
def proc(&prc)
729-
raise ArgumentError, "block required" unless prc
730-
return prc
728+
def proc
729+
env = nil
730+
731+
Rubinius.asm do
732+
push_block
733+
# assign a pushed block to the above local variable "env"
734+
set_local 0
735+
end
736+
737+
unless env
738+
# Support for ancient pre-block-pass style:
739+
# def something
740+
# proc
741+
# end
742+
# something { a_block } => Proc instance
743+
env = Rubinius::BlockEnvironment.of_sender
744+
745+
unless env
746+
raise ArgumentError, "tried to create a Proc object without a block"
747+
end
748+
end
749+
750+
Proc.new(&env)
731751
end
732752
module_function :proc
733753

Diff for: ‎spec/tags/ruby/core/kernel/proc_tags.txt

-1
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.