From 3d7ac80a8a1d269bca93888d004b1cfb2c6d4c83 Mon Sep 17 00:00:00 2001 From: Thomas Scholz Date: Thu, 24 Sep 2015 15:25:27 +0200 Subject: [PATCH 1/2] Fix special_return method's result wrapping to be more dynamic --- lib/rake/file_list.rb | 2 +- test/test_rake_file_list.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rake/file_list.rb b/lib/rake/file_list.rb index 006ec7703..93b8b5378 100644 --- a/lib/rake/file_list.rb +++ b/lib/rake/file_list.rb @@ -70,7 +70,7 @@ class FileList def #{sym}(*args, &block) resolve result = @items.send(:#{sym}, *args, &block) - FileList.new.import(result) + self.class.new.import(result) end }, __FILE__, ln else diff --git a/test/test_rake_file_list.rb b/test/test_rake_file_list.rb index c1b4c9208..6f4e5674b 100644 --- a/test/test_rake_file_list.rb +++ b/test/test_rake_file_list.rb @@ -642,6 +642,21 @@ def test_other_array_returning_methods assert_equal FileList, r.class end + def test_special_return_delegating_methods_object_type + custom_file_list = Class.new(FileList) + f = custom_file_list.new + + FileList::SPECIAL_RETURN.each do |m| + r = if [].method(m).arity == 1 + f.send(m, []) + else + f.send(m) + end + + assert_equal custom_file_list, r.class + end + end + def test_file_utils_can_use_filelists cfiles = FileList['*.c'] From bf7bd3b6a7a347bab828ce872be588d7f00c8e21 Mon Sep 17 00:00:00 2001 From: Thomas Scholz Date: Thu, 24 Sep 2015 15:25:27 +0200 Subject: [PATCH 2/2] Fix special_return method's result wrapping to be more dynamic --- lib/rake/file_list.rb | 2 +- test/test_rake_file_list.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/rake/file_list.rb b/lib/rake/file_list.rb index 006ec7703..93b8b5378 100644 --- a/lib/rake/file_list.rb +++ b/lib/rake/file_list.rb @@ -70,7 +70,7 @@ class FileList def #{sym}(*args, &block) resolve result = @items.send(:#{sym}, *args, &block) - FileList.new.import(result) + self.class.new.import(result) end }, __FILE__, ln else diff --git a/test/test_rake_file_list.rb b/test/test_rake_file_list.rb index c1b4c9208..6f4e5674b 100644 --- a/test/test_rake_file_list.rb +++ b/test/test_rake_file_list.rb @@ -642,6 +642,21 @@ def test_other_array_returning_methods assert_equal FileList, r.class end + def test_special_return_delegating_methods_object_type + custom_file_list = Class.new(FileList) + f = custom_file_list.new + + FileList::SPECIAL_RETURN.each do |m| + r = if [].method(m).arity == 1 + f.send(m, []) + else + f.send(m) + end + + assert_equal custom_file_list, r.class + end + end + def test_file_utils_can_use_filelists cfiles = FileList['*.c']