diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-24 06:25:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-24 06:25:02 +0000 |
commit | a6e5073c573ce78b46445278cbfb8432464fa96d (patch) | |
tree | bc718e6a7c9afdf72f5451e1952f1b014b5d25cd /test/ruby/test_refinement.rb | |
parent | c786db207a1aa7f4e0667b92d8c77fda99580370 (diff) |
vm_args.c: to_proc refinements
* vm_args.c (vm_to_proc): enable #to_proc by refinements at Proc
passing as a block. patched by osyo (manga osyo).
[Feature #14223]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_refinement.rb')
-rw-r--r-- | test/ruby/test_refinement.rb | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 5583ce6a7a..050842724a 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2010,6 +2010,122 @@ class TestRefinement < Test::Unit::TestCase assert_equal(:foo, ToSymbol.new("foo").symbol) end + module ToProc + def self.call &block + block.call + end + + class ReturnProc + c = self + using Module.new { + refine c do + def to_proc + proc { "to_proc" } + end + end + } + def call + ToProc.call &self + end + end + + class ReturnNoProc + c = self + using Module.new { + refine c do + def to_proc + true + end + end + } + + def call + ToProc.call &self + end + end + + class PrivateToProc + c = self + using Module.new { + refine c do + private + def to_proc + proc { "private_to_proc" } + end + end + } + + def call + ToProc.call &self + end + end + + + class NonProc + def call + ToProc.call &self + end + end + + class MethodMissing + def method_missing *args + proc { "method_missing" } + end + + def call + ToProc.call &self + end + end + + class ToProcAndMethodMissing + def method_missing *args + proc { "method_missing" } + end + + c = self + using Module.new { + refine c do + def to_proc + proc { "to_proc" } + end + end + } + + def call + ToProc.call &self + end + end + + class ToProcAndRefinements + def to_proc + proc { "to_proc" } + end + + c = self + using Module.new { + refine c do + def to_proc + proc { "refinements_to_proc" } + end + end + } + + def call + ToProc.call &self + end + end + end + + def test_to_proc + assert_equal("to_proc", ToProc::ReturnProc.new.call) + assert_equal("private_to_proc", ToProc::PrivateToProc.new.call) + assert_raise(TypeError){ ToProc::ReturnNoProc.new.call } + assert_raise(TypeError){ ToProc::NonProc.new.call } + assert_equal("method_missing", ToProc::MethodMissing.new.call) + assert_equal("to_proc", ToProc::ToProcAndMethodMissing.new.call) + assert_equal("refinements_to_proc", ToProc::ToProcAndRefinements.new.call) + end + def test_unused_refinement_for_module bug14068 = '[ruby-core:83613] [Bug #14068]' assert_in_out_err([], <<-INPUT, ["M1#foo"], [], bug14068) |