Skip to content

Commit

Permalink
Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Jan 23, 2015
1 parent 04dc46f commit 96b61f1
Show file tree
Hide file tree
Showing 31 changed files with 733 additions and 721 deletions.
2 changes: 1 addition & 1 deletion lib/pry/code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def initialize(lines = [], start_line = 1, code_type = :ruby)
LOC.new(line, lineno + start_line.to_i) }
@code_type = code_type

@with_marker = @with_indentation = nil
@with_marker = @with_indentation = @with_line_numbers = nil
end

# Append the given line. +lineno+ is one more than the last existing
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def command_options(arg=nil)
# Define or get the command's banner
def banner(arg=nil)
@banner = arg if arg
@banner || description
@banner ||= description
end

def block
Expand Down
1 change: 1 addition & 0 deletions lib/pry/commands/ls/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Formatter
def initialize(_pry_)
@_pry_ = _pry_
@target = _pry_.current_context
@default_switch = nil
end

def write_out
Expand Down
6 changes: 4 additions & 2 deletions lib/pry/config/behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ def __dup(value)
end

def __push(key,value)
define_singleton_method(key) { self[key] }
define_singleton_method("#{key}=") { |val| @lookup[key] = val }
unless singleton_class.method_defined? key
define_singleton_method(key) { self[key] }
define_singleton_method("#{key}=") { |val| @lookup[key] = val }
end
@lookup[key] = value
end

Expand Down
236 changes: 118 additions & 118 deletions lib/pry/input_completer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,137 +106,137 @@ def call(str, options = {})
begin
context = target.eval("self")
context = context.class unless context.respond_to? :constants
candidates = context.constants.collect(&:to_s)
rescue
candidates = []
end
candidates = candidates.grep(/^#{message}/).collect(&path)
when CONSTANT_OR_METHOD_REGEXP # Constant or class methods
receiver = $1
message = Regexp.quote($2)
begin
candidates = eval("#{receiver}.constants.collect(&:to_s)", bind)
candidates |= eval("#{receiver}.methods.collect(&:to_s)", bind)
rescue Pry::RescuableException
candidates = []
end
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
when SYMBOL_METHOD_CALL_REGEXP # method call on a Symbol
receiver = $1
message = Regexp.quote($2)
candidates = Symbol.instance_methods.collect(&:to_s)
select_message(path, receiver, message, candidates)
when NUMERIC_REGEXP
# Numeric
receiver = $1
message = Regexp.quote($5)
begin
candidates = eval(receiver, bind).methods.collect(&:to_s)
rescue Pry::RescuableException
candidates = []
end
select_message(path, receiver, message, candidates)
when HEX_REGEXP
# Numeric(0xFFFF)
receiver = $1
message = Regexp.quote($2)
candidates = context.constants.collect(&:to_s)
rescue
candidates = []
end
candidates = candidates.grep(/^#{message}/).collect(&path)
when CONSTANT_OR_METHOD_REGEXP # Constant or class methods
receiver = $1
message = Regexp.quote($2)
begin
candidates = eval("#{receiver}.constants.collect(&:to_s)", bind)
candidates |= eval("#{receiver}.methods.collect(&:to_s)", bind)
rescue Pry::RescuableException
candidates = []
end
candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
when SYMBOL_METHOD_CALL_REGEXP # method call on a Symbol
receiver = $1
message = Regexp.quote($2)
candidates = Symbol.instance_methods.collect(&:to_s)
select_message(path, receiver, message, candidates)
when NUMERIC_REGEXP
# Numeric
receiver = $1
message = Regexp.quote($5)
begin
candidates = eval(receiver, bind).methods.collect(&:to_s)
rescue Pry::RescuableException
candidates = []
end
select_message(path, receiver, message, candidates)
when HEX_REGEXP
# Numeric(0xFFFF)
receiver = $1
message = Regexp.quote($2)
begin
candidates = eval(receiver, bind).methods.collect(&:to_s)
rescue Pry::RescuableException
candidates = []
end
select_message(path, receiver, message, candidates)
when GLOBALVARIABLE_REGEXP # global
regmessage = Regexp.new(Regexp.quote($1))
candidates = global_variables.collect(&:to_s).grep(regmessage)
when VARIABLE_REGEXP # variable
receiver = $1
message = Regexp.quote($2)

gv = eval("global_variables", bind).collect(&:to_s)
lv = eval("local_variables", bind).collect(&:to_s)
cv = eval("self.class.constants", bind).collect(&:to_s)

if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
# foo.func and foo is local var. OR
# Foo::Bar.func
begin
candidates = eval(receiver, bind).methods.collect(&:to_s)
candidates = eval("#{receiver}.methods", bind).collect(&:to_s)
rescue Pry::RescuableException
candidates = []
end
select_message(path, receiver, message, candidates)
when GLOBALVARIABLE_REGEXP # global
regmessage = Regexp.new(Regexp.quote($1))
candidates = global_variables.collect(&:to_s).grep(regmessage)
when VARIABLE_REGEXP # variable
receiver = $1
message = Regexp.quote($2)

gv = eval("global_variables", bind).collect(&:to_s)
lv = eval("local_variables", bind).collect(&:to_s)
cv = eval("self.class.constants", bind).collect(&:to_s)

if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
# foo.func and foo is local var. OR
# Foo::Bar.func
else
# func1.func2
candidates = []
ObjectSpace.each_object(Module){|m|
begin
candidates = eval("#{receiver}.methods", bind).collect(&:to_s)
name = m.name.to_s
rescue Pry::RescuableException
candidates = []
name = ""
end
else
# func1.func2
candidates = []
ObjectSpace.each_object(Module){|m|
begin
name = m.name.to_s
rescue Pry::RescuableException
name = ""
end
next if name != "IRB::Context" and
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name

# jruby doesn't always provide #instance_methods() on each
# object.
if m.respond_to?(:instance_methods)
candidates.concat m.instance_methods(false).collect(&:to_s)
end
}
candidates.sort!
candidates.uniq!
end
select_message(path, receiver, message, candidates)
when /^\.([^.]*)$/
# Unknown(maybe String)
receiver = ""
message = Regexp.quote($1)
candidates = String.instance_methods(true).collect(&:to_s)
select_message(path, receiver, message, candidates)
else
candidates = eval(
"methods | private_methods | local_variables | " \
"self.class.constants | instance_variables",
bind
).collect(&:to_s)
next if name != "IRB::Context" and
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name

if eval("respond_to?(:class_variables)", bind)
candidates += eval("class_variables", bind).collect(&:to_s)
end
candidates = (candidates|ReservedWords|custom_completions).grep(/^#{Regexp.quote(input)}/)
candidates.collect(&path)
# jruby doesn't always provide #instance_methods() on each
# object.
if m.respond_to?(:instance_methods)
candidates.concat m.instance_methods(false).collect(&:to_s)
end
}
candidates.sort!
candidates.uniq!
end
rescue Pry::RescuableException
[]
end
end
select_message(path, receiver, message, candidates)
when /^\.([^.]*)$/
# Unknown(maybe String)
receiver = ""
message = Regexp.quote($1)
candidates = String.instance_methods(true).collect(&:to_s)
select_message(path, receiver, message, candidates)
else
candidates = eval(
"methods | private_methods | local_variables | " \
"self.class.constants | instance_variables",
bind
).collect(&:to_s)

def select_message(path, receiver, message, candidates)
candidates.grep(/^#{message}/).collect { |e|
case e
when /^[a-zA-Z_]/
path.call(receiver + "." << e)
when /^[0-9]/
when *Operators
#receiver + " " << e
if eval("respond_to?(:class_variables)", bind)
candidates += eval("class_variables", bind).collect(&:to_s)
end
}.compact
candidates = (candidates|ReservedWords|custom_completions).grep(/^#{Regexp.quote(input)}/)
candidates.collect(&path)
end
rescue Pry::RescuableException
[]
end
end

# build_path seperates the input into two parts: path and input.
# input is the partial string that should be completed
# path is a proc that takes an input and builds a full path.
def build_path(input)
# check to see if the input is a regex
return proc {|i| i.to_s }, input if input[/\/\./]
trailing_slash = input.end_with?('/')
contexts = input.chomp('/').split(/\//)
input = contexts[-1]
path = proc do |i|
p = contexts[0..-2].push(i).join('/')
p += '/' if trailing_slash && !i.nil?
p
def select_message(path, receiver, message, candidates)
candidates.grep(/^#{message}/).collect { |e|
case e
when /^[a-zA-Z_]/
path.call(receiver + "." << e)
when /^[0-9]/
when *Operators
#receiver + " " << e
end
return path, input
}.compact
end

# build_path seperates the input into two parts: path and input.
# input is the partial string that should be completed
# path is a proc that takes an input and builds a full path.
def build_path(input)
# check to see if the input is a regex
return proc {|i| i.to_s }, input if input[/\/\./]
trailing_slash = input.end_with?('/')
contexts = input.chomp('/').split(/\//)
input = contexts[-1]
path = proc do |i|
p = contexts[0..-2].push(i).join('/')
p += '/' if trailing_slash && !i.nil?
p
end
return path, input
end
end
1 change: 1 addition & 0 deletions lib/pry/method/disowned.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Disowned < Method
# @param [String] method_name
def initialize(receiver, method_name, binding=nil)
@receiver, @name = receiver, method_name
@method = nil
end

# Is the method undefined? (aka `Disowned`)
Expand Down
6 changes: 2 additions & 4 deletions lib/pry/module_candidate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ def source
return nil if file.nil?
return @source if @source

@source = strip_leading_whitespace(Pry::Code.from_file(file).expression_at(line, number_of_lines_in_first_chunk))
@source ||= strip_leading_whitespace(Pry::Code.from_file(file).expression_at(line, number_of_lines_in_first_chunk))
end

# @raise [Pry::CommandError] If documentation cannot be found.
# @return [String] The documentation for the candidate.
def doc
return nil if file.nil?
return @doc if @doc

@doc = get_comment_content(Pry::Code.from_file(file).comment_describing(line))
@doc ||= get_comment_content(Pry::Code.from_file(file).comment_describing(line))
end

# @return [Array, nil] A `[String, Fixnum]` pair representing the
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def temp_file(ext='.rb')
yield file
ensure
file.close(true) if file
File.unlink("#{file.path}c") if File.exists?("#{file.path}c") # rbx
File.unlink("#{file.path}c") if File.exist?("#{file.path}c") # rbx
end

def unindent(*args)
Expand Down
Loading

0 comments on commit 96b61f1

Please sign in to comment.