-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use delegator to install helper methods to main object
IRB used delegator to install command as a method of frozen main object. Command is not a method now. We can drop it.
- Loading branch information
Showing
6 changed files
with
50 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ | |
# by Keiju ISHITSUKA([email protected]) | ||
# | ||
|
||
require "delegate" | ||
|
||
require_relative "helper_method" | ||
|
||
IRB::TOPLEVEL_BINDING = binding | ||
|
@@ -16,7 +14,7 @@ class WorkSpace | |
# set self to main if specified, otherwise | ||
# inherit main from TOPLEVEL_BINDING. | ||
def initialize(*main) | ||
if main[0].kind_of?(Binding) | ||
if Binding === main[0] | ||
@binding = main.shift | ||
elsif IRB.conf[:SINGLE_IRB] | ||
@binding = TOPLEVEL_BINDING | ||
|
@@ -70,37 +68,16 @@ def initialize(*main) | |
unless main.empty? | ||
case @main | ||
when Module | ||
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__) | ||
@binding = eval("::IRB.conf[:__MAIN__].module_eval('::Kernel.binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__) | ||
else | ||
begin | ||
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__) | ||
@binding = eval("::IRB.conf[:__MAIN__].instance_eval('::Kernel.binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__) | ||
rescue TypeError | ||
fail CantChangeBinding, @main.inspect | ||
end | ||
end | ||
end | ||
|
||
case @main | ||
when Object | ||
use_delegator = @main.frozen? | ||
else | ||
use_delegator = true | ||
end | ||
|
||
if use_delegator | ||
@main = SimpleDelegator.new(@main) | ||
IRB.conf[:__MAIN__] = @main | ||
@main.singleton_class.class_eval do | ||
private | ||
define_method(:binding, Kernel.instance_method(:binding)) | ||
define_method(:local_variables, Kernel.instance_method(:local_variables)) | ||
# Define empty method to avoid delegator warning, will be overridden. | ||
define_method(:exit) {|*a, &b| } | ||
define_method(:exit!) {|*a, &b| } | ||
end | ||
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location) | ||
end | ||
|
||
@binding.local_variable_set(:_, nil) | ||
end | ||
|
||
|
@@ -111,6 +88,8 @@ def initialize(*main) | |
attr_reader :main | ||
|
||
def load_helper_methods_to_main | ||
# Do not load helper methods to frozen objects and BasicObject | ||
return unless Object === @main && !@main.frozen? | ||
ancestors = class<<main;ancestors;end | ||
main.extend ExtendCommandBundle if !ancestors.include?(ExtendCommandBundle) | ||
main.extend HelpersContainer if !ancestors.include?(HelpersContainer) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters