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)
|
||||
file, _ = meth.source_location
|
||||
if file =~ /(\(.*\))|<.*>/
|
||||
if file =~ /(\(.*\))|<.*>/ && file != "(pry)"
|
||||
raise "Cannot retrieve source for dynamically defined method."
|
||||
end
|
||||
end
|
||||
|
@ -61,7 +61,11 @@ class Pry
|
|||
code = Pry::MethodInfo.info_for(meth).source
|
||||
code = strip_comments_from_c_code(code)
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -116,6 +116,12 @@ class Pry
|
|||
# @return [OpenStruct] Return Pry's config object.
|
||||
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
|
||||
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
||||
|
||||
|
@ -226,7 +232,7 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def self.set_config_options
|
||||
def self.set_config_defaults
|
||||
config.input = Readline
|
||||
config.output = $stdout
|
||||
config.commands = Pry::Commands
|
||||
|
@ -241,12 +247,14 @@ class Pry
|
|||
|
||||
# Set all the configurable options back to their default values
|
||||
def self.reset_defaults
|
||||
set_config_options
|
||||
set_config_defaults
|
||||
|
||||
@custom_completions = DEFAULT_CUSTOM_COMPLETIONS
|
||||
@should_load_rc = true
|
||||
@rc_loaded = false
|
||||
@cli = false
|
||||
@current_expr = -1
|
||||
@expr_store = []
|
||||
end
|
||||
|
||||
# Basic initialization.
|
||||
|
|
|
@ -27,10 +27,10 @@ class Pry
|
|||
# component of the REPL. (see print.rb)
|
||||
def initialize(options={})
|
||||
defaults = {}
|
||||
attributes = [
|
||||
attributes = [
|
||||
:input, :output, :commands, :print,
|
||||
:exception_handler, :hooks, :custom_completions,
|
||||
:prompt
|
||||
:prompt
|
||||
]
|
||||
|
||||
attributes.each do |attribute|
|
||||
|
@ -40,13 +40,13 @@ class Pry
|
|||
defaults.merge!(options).each_key do |key|
|
||||
send "#{key}=", defaults[key]
|
||||
end
|
||||
|
||||
|
||||
@command_processor = CommandProcessor.new(self)
|
||||
end
|
||||
|
||||
# The current prompt.
|
||||
# The current prompt.
|
||||
# This is the prompt at the top of the prompt stack.
|
||||
#
|
||||
#
|
||||
# @example
|
||||
# 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
|
||||
# (eval) methods for show-method and friends.
|
||||
# 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
|
||||
exit
|
||||
rescue Exception => e
|
||||
|
|
Loading…
Reference in a new issue