From e5ca3d072fd1076133dc7c3a9a2e399bbfcee443 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 24 Apr 2024 16:59:39 +0100 Subject: [ruby/irb] Memoize helper method instances with Singleton module Some helpers, like Rails console's `app`, requires memoization of the helper's ivars. To support it IRB needs to memoize helper method instances as well. https://github.com/ruby/irb/commit/169a9a2c30 --- lib/irb/helper_method/base.rb | 4 ++++ lib/irb/workspace.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/irb/helper_method/base.rb b/lib/irb/helper_method/base.rb index dc74b046da..a68001ed28 100644 --- a/lib/irb/helper_method/base.rb +++ b/lib/irb/helper_method/base.rb @@ -1,6 +1,10 @@ +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 dd92d99014..d24d1cc38d 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.new.execute(*args, **opts, &block) + helper_method_class.instance.execute(*args, **opts, &block) end unless method_defined?(name) end end -- cgit v1.2.3