Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unroll extension method generation #882

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions lib/irb/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,44 +315,4 @@ def self.extend_object(obj)

install_extend_commands
end

# Extends methods for the Context module
module ContextExtender
CE = ContextExtender # :nodoc:

@EXTEND_COMMANDS = [
[:eval_history=, "ext/eval_history.rb"],
[:use_loader=, "ext/use-loader.rb"],
]

# Installs the default context extensions as irb commands:
#
# Context#eval_history=:: +irb/ext/history.rb+
# Context#use_tracer=:: +irb/ext/tracer.rb+
# Context#use_loader=:: +irb/ext/use-loader.rb+
def self.install_extend_commands
for args in @EXTEND_COMMANDS
def_extend_command(*args)
end
end

# Evaluate the given +command+ from the given +load_file+ on the Context
# module.
#
# Will also define any given +aliases+ for the method.
def self.def_extend_command(cmd_name, load_file, *aliases)
line = __LINE__; Context.module_eval %[
def #{cmd_name}(*opts, &b)
Context.module_eval {remove_method(:#{cmd_name})}
require_relative "#{load_file}"
__send__ :#{cmd_name}, *opts, &b
end
for ali in aliases
alias_method ali, cmd_name
end
], __FILE__, line
end

CE.install_extend_commands
end
end
12 changes: 12 additions & 0 deletions lib/irb/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ def use_tracer=(val)
IRB.conf[:USE_TRACER] = val
end

def eval_history=(val)
self.class.remove_method(__method__)
require_relative "ext/eval_history"
__send__(__method__, val)
end

def use_loader=(val)
self.class.remove_method(__method__)
require_relative "ext/use-loader"
__send__(__method__, val)
end

private def build_completor
completor_type = IRB.conf[:COMPLETOR]
case completor_type
Expand Down
4 changes: 2 additions & 2 deletions lib/irb/ext/use-loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
#

require_relative "../cmd/load"
require_relative "../command/load"
require_relative "loader"

class Object
Expand Down Expand Up @@ -49,7 +49,7 @@ def use_loader=(opt)
if IRB.conf[:USE_LOADER] != opt
IRB.conf[:USE_LOADER] = opt
if opt
if !$".include?("irb/cmd/load")
if !$".include?("irb/command/load")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if seems doing nothing from the beginning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! #885

end
(class<<@workspace.main;self;end).instance_eval {
alias_method :load, :irb_load
Expand Down
Loading