mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
first attempt at bringing show-method to eval methods
This commit is contained in:
parent
198cff4349
commit
07046765ee
3 changed files with 25 additions and 10 deletions
|
@ -43,7 +43,7 @@ class Pry
|
||||||
|
|
||||||
def check_for_dynamically_defined_method(meth)
|
def check_for_dynamically_defined_method(meth)
|
||||||
file, _ = meth.source_location
|
file, _ = meth.source_location
|
||||||
if file =~ /(\(.*\))|<.*>/
|
if file =~ /(\(.*\))|<.*>/ && file != "(pry)"
|
||||||
raise "Cannot retrieve source for dynamically defined method."
|
raise "Cannot retrieve source for dynamically defined method."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -61,7 +61,11 @@ class Pry
|
||||||
code = Pry::MethodInfo.info_for(meth).source
|
code = Pry::MethodInfo.info_for(meth).source
|
||||||
code = strip_comments_from_c_code(code)
|
code = strip_comments_from_c_code(code)
|
||||||
when :ruby
|
when :ruby
|
||||||
code = strip_leading_whitespace(meth.source)
|
if meth.source_location.first == "(pry)"
|
||||||
|
code = strip_leading_whitespace(Pry.expr_store[meth.source_location.last])
|
||||||
|
else
|
||||||
|
code = strip_leading_whitespace(meth.source)
|
||||||
|
end
|
||||||
set_file_and_dir_locals(meth.source_location.first)
|
set_file_and_dir_locals(meth.source_location.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,12 @@ class Pry
|
||||||
# @return [OpenStruct] Return Pry's config object.
|
# @return [OpenStruct] Return Pry's config object.
|
||||||
attr_accessor :config
|
attr_accessor :config
|
||||||
|
|
||||||
|
# @return [Fixnum] The current input line.
|
||||||
|
attr_accessor :current_expr
|
||||||
|
|
||||||
|
# @return [Array] The Array of evaluated expressions.
|
||||||
|
attr_accessor :expr_store
|
||||||
|
|
||||||
# plugin forwardables
|
# plugin forwardables
|
||||||
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
||||||
|
|
||||||
|
@ -226,7 +232,7 @@ class Pry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.set_config_options
|
def self.set_config_defaults
|
||||||
config.input = Readline
|
config.input = Readline
|
||||||
config.output = $stdout
|
config.output = $stdout
|
||||||
config.commands = Pry::Commands
|
config.commands = Pry::Commands
|
||||||
|
@ -241,12 +247,14 @@ class Pry
|
||||||
|
|
||||||
# Set all the configurable options back to their default values
|
# Set all the configurable options back to their default values
|
||||||
def self.reset_defaults
|
def self.reset_defaults
|
||||||
set_config_options
|
set_config_defaults
|
||||||
|
|
||||||
@custom_completions = DEFAULT_CUSTOM_COMPLETIONS
|
@custom_completions = DEFAULT_CUSTOM_COMPLETIONS
|
||||||
@should_load_rc = true
|
@should_load_rc = true
|
||||||
@rc_loaded = false
|
@rc_loaded = false
|
||||||
@cli = false
|
@cli = false
|
||||||
|
@current_expr = -1
|
||||||
|
@expr_store = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Basic initialization.
|
# Basic initialization.
|
||||||
|
|
|
@ -27,10 +27,10 @@ class Pry
|
||||||
# component of the REPL. (see print.rb)
|
# component of the REPL. (see print.rb)
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
defaults = {}
|
defaults = {}
|
||||||
attributes = [
|
attributes = [
|
||||||
:input, :output, :commands, :print,
|
:input, :output, :commands, :print,
|
||||||
:exception_handler, :hooks, :custom_completions,
|
:exception_handler, :hooks, :custom_completions,
|
||||||
:prompt
|
:prompt
|
||||||
]
|
]
|
||||||
|
|
||||||
attributes.each do |attribute|
|
attributes.each do |attribute|
|
||||||
|
@ -40,13 +40,13 @@ class Pry
|
||||||
defaults.merge!(options).each_key do |key|
|
defaults.merge!(options).each_key do |key|
|
||||||
send "#{key}=", defaults[key]
|
send "#{key}=", defaults[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
@command_processor = CommandProcessor.new(self)
|
@command_processor = CommandProcessor.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The current prompt.
|
# The current prompt.
|
||||||
# This is the prompt at the top of the prompt stack.
|
# This is the prompt at the top of the prompt stack.
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
# self.prompt = Pry::SIMPLE_PROMPT
|
# self.prompt = Pry::SIMPLE_PROMPT
|
||||||
# self.prompt # => Pry::SIMPLE_PROMPT
|
# self.prompt # => Pry::SIMPLE_PROMPT
|
||||||
|
@ -189,7 +189,10 @@ class Pry
|
||||||
# Do not want __FILE__, __LINE__ here because we need to distinguish
|
# Do not want __FILE__, __LINE__ here because we need to distinguish
|
||||||
# (eval) methods for show-method and friends.
|
# (eval) methods for show-method and friends.
|
||||||
# This also sets the `_` local for the session.
|
# This also sets the `_` local for the session.
|
||||||
set_last_result(target.eval(r(target)), target)
|
expr = r(target)
|
||||||
|
|
||||||
|
Pry.expr_store << expr
|
||||||
|
set_last_result(target.eval(expr, "(pry)", Pry.current_expr += 1), target)
|
||||||
rescue SystemExit => e
|
rescue SystemExit => e
|
||||||
exit
|
exit
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue