Skip to content

Commit

Permalink
[ruby/irb] Remove dead code (ruby/irb#554)
Browse files Browse the repository at this point in the history
* Remove unused ATTR_TTY and ATTR_PLAIN constants

They were added in ruby/irb@d7d26b5

But the references were removed in ruby/irb@1c76845

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

* Remove unused MethodExtender module

It was added in ruby/irb@6cc5d71
but it's not used anywhere.

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

* Remove unused IRB.irb_at_exit

It's not used after ruby/irb@aaf4eb4

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>

* Remove unused InputCompletor.ignored_modules

It was added in ruby/irb@88311ce
but the reference was removed in ruby/irb@78c74d2

* Remove unused TracerLoadError constant

This constant was added in ruby/irb@cb50fa3
but never referenced.

---------

ruby/irb@7de0234325

Co-authored-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
2 people authored and matzbot committed Apr 2, 2023
1 parent 9e1ff24 commit f257918
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 90 deletions.
10 changes: 0 additions & 10 deletions lib/irb.rb
Expand Up @@ -416,11 +416,6 @@ def IRB.start(ap_path = nil)
irb.run(@CONF)
end

# Calls each event hook of <code>IRB.conf[:AT_EXIT]</code> when the current session quits.
def IRB.irb_at_exit
@CONF[:AT_EXIT].each{|hook| hook.call}
end

# Quits irb
def IRB.irb_exit(irb, ret)
throw :IRB_EXIT, ret
Expand Down Expand Up @@ -897,11 +892,6 @@ def assignment_expression?(line)
ensure
$VERBOSE = verbose
end

ATTR_TTY = "\e[%sm"
def ATTR_TTY.[](*a) self % a.join(";"); end
ATTR_PLAIN = ""
def ATTR_PLAIN.[](*) self; end
end

def @CONF.inspect
Expand Down
25 changes: 0 additions & 25 deletions lib/irb/completion.rb
Expand Up @@ -450,30 +450,5 @@ def self.select_message(receiver, message, candidates, sep = ".")
end
end
end

def self.ignored_modules
# We could cache the result, but this is very fast already.
# By using this approach, we avoid Module#name calls, which are
# relatively slow when there are a lot of anonymous modules defined.
s = {}

scanner = lambda do |m|
next if s.include?(m) # IRB::ExtendCommandBundle::EXCB recurses.
s[m] = true
m.constants(false).each do |c|
value = m.const_get(c)
scanner.call(value) if value.is_a?(Module)
end
end

%i(IRB RubyLex).each do |sym|
next unless Object.const_defined?(sym)
scanner.call(Object.const_get(sym))
end

s.delete(IRB::Context) if defined?(IRB::Context)

s
end
end
end
1 change: 0 additions & 1 deletion lib/irb/ext/tracer.rb
Expand Up @@ -9,7 +9,6 @@
rescue LoadError
$stderr.puts "Tracer extension of IRB is enabled but tracer gem doesn't found."
module IRB
TracerLoadError = true
class Context
def use_tracer=(opt)
# do nothing
Expand Down
54 changes: 0 additions & 54 deletions lib/irb/extend-command.rb
Expand Up @@ -371,58 +371,4 @@ def #{cmd_name}(*opts, &b)

CE.install_extend_commands
end

# A convenience module for extending Ruby methods.
module MethodExtender
# Extends the given +base_method+ with a prefix call to the given
# +extend_method+.
def def_pre_proc(base_method, extend_method)
base_method = base_method.to_s
extend_method = extend_method.to_s

alias_name = new_alias_name(base_method)
module_eval %[
alias_method alias_name, base_method
def #{base_method}(*opts)
__send__ :#{extend_method}, *opts
__send__ :#{alias_name}, *opts
end
]
end

# Extends the given +base_method+ with a postfix call to the given
# +extend_method+.
def def_post_proc(base_method, extend_method)
base_method = base_method.to_s
extend_method = extend_method.to_s

alias_name = new_alias_name(base_method)
module_eval %[
alias_method alias_name, base_method
def #{base_method}(*opts)
__send__ :#{alias_name}, *opts
__send__ :#{extend_method}, *opts
end
]
end

# Returns a unique method name to use as an alias for the given +name+.
#
# Usually returns <code>#{prefix}#{name}#{postfix}<num></code>, example:
#
# new_alias_name('foo') #=> __alias_of__foo__
# def bar; end
# new_alias_name('bar') #=> __alias_of__bar__2
def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
base_name = "#{prefix}#{name}#{postfix}"
all_methods = instance_methods(true) + private_instance_methods(true)
same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/)
return base_name if same_methods.empty?
no = same_methods.size
while !same_methods.include?(alias_name = base_name + no)
no += 1
end
alias_name
end
end
end

0 comments on commit f257918

Please sign in to comment.