summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2024-04-24 17:01:14 +0100
committergit <svn-admin@ruby-lang.org>2024-04-24 16:01:23 +0000
commit9bba999be7b32949b4b37dd7a871c5dc1e36c2f8 (patch)
treeaf5b29d52cb0774ca2bfdf8cc808a96daa1a0d47
parente5ca3d072fd1076133dc7c3a9a2e399bbfcee443 (diff)
[ruby/irb] Revert "Memoize helper method instances with Singleton module"
This reverts commit https://github.com/ruby/irb/commit/169a9a2c3097. https://github.com/ruby/irb/commit/221b0a4928
-rw-r--r--lib/irb/helper_method/base.rb4
-rw-r--r--lib/irb/workspace.rb2
-rw-r--r--test/irb/test_helper_method.rb31
3 files changed, 4 insertions, 33 deletions
diff --git a/lib/irb/helper_method/base.rb b/lib/irb/helper_method/base.rb
index a68001ed28..dc74b046da 100644
--- a/lib/irb/helper_method/base.rb
+++ b/lib/irb/helper_method/base.rb
@@ -1,10 +1,6 @@
-require "singleton"
-
module IRB
module HelperMethod
class Base
- include Singleton
-
class << self
def description(description = nil)
@description = description if description
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index d24d1cc38d..dd92d99014 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -179,7 +179,7 @@ EOF
def self.install_helper_methods
HelperMethod.helper_methods.each do |name, helper_method_class|
define_method name do |*args, **opts, &block|
- helper_method_class.instance.execute(*args, **opts, &block)
+ helper_method_class.new.execute(*args, **opts, &block)
end unless method_defined?(name)
end
end
diff --git a/test/irb/test_helper_method.rb b/test/irb/test_helper_method.rb
index 291278c16a..5174e5ceb2 100644
--- a/test/irb/test_helper_method.rb
+++ b/test/irb/test_helper_method.rb
@@ -97,38 +97,13 @@ module TestIRB
RUBY
output = run_ruby_file do
- type "my_helper"
+ type <<~INPUT
+ my_helper
+ INPUT
type "exit"
end
assert_include(output, 'Hello from MyHelper')
end
-
- def test_helper_method_instances_are_memoized
- write_ruby <<~RUBY
- require "irb/helper_method"
-
- class MyHelper < IRB::HelperMethod::Base
- description "This is a test helper"
-
- def execute(val)
- @val ||= val
- end
- end
-
- IRB::HelperMethod.register(:my_helper, MyHelper)
-
- binding.irb
- RUBY
-
- output = run_ruby_file do
- type "my_helper(100)"
- type "my_helper(200)"
- type "exit"
- end
-
- assert_include(output, '=> 100')
- assert_not_include(output, '=> 200')
- end
end
end