Deal with the ^D key being pressed. Different behaviour in different cases:

In an expression behave like ! command.

At top-level session behave like exit command.

In a nested session behave like cd ...

procdo|eval_string,_pry_|if!eval_string.empty?eval_string.replace('')# Clear input buffer.elsif_pry_.binding_stack.one?_pry_.binding_stack.clearthrow(:breakout)else# Otherwise, saves current binding stack as old stack and pops last# binding out of binding stack (the old stack still has that binding)._pry_.command_state["cd"]||=Pry::Config.from_hash({})# FIXME_pry_.command_state['cd'].old_stack=_pry_.binding_stack.dup_pry_.binding_stack.popendend

DEFAULT_SYSTEM =

procdo|output,cmd,_|if!system(cmd)output.puts"Error: there was a problem executing system command: #{cmd}"endend

INITIAL_PWD =

Store the current working directory. This allows show-source etc. to work if
your process has changed directory since boot. [Issue #675]

Dir.pwd

VERSION =

"0.11.3"

Commands =

Default commands used by Pry.

Pry::CommandSet.new

HOME_RC_FILE =

ENV["PRYRC"]||"~/.pryrc"

LOCAL_RC_FILE =

"./.pryrc"

DEFAULT_EXCEPTION_WHITELIST =

Don't catch these exceptions

[SystemExit,SignalException,Pry::TooSafeException]

EMPTY_COMPLETIONS =

[].freeze

BINDING_METHOD_IMPL =

Returns Code of the method used when implementing Pry's
binding, along with line indication to be used with instance_eval (and
friends).

Returns:

(Array)
—

Code of the method used when implementing Pry's
binding, along with line indication to be used with instance_eval (and
friends).

["# Get a binding with 'self' set to self, and no locals.\n#\n# The default definee is determined by the context in which the\n# definition is eval'd.\n#\n# Please don't call this method directly, see {__binding__}.\n#\n# @return [Binding]\ndef __pry__\nbinding\nend\n",__FILE__,__LINE__+1]

Potentially deprecated — Use Pry::REPL.new(pry, :target => target).start (If nested sessions are going to exist, this method is fine, but a goal is to come up with an alternative to nested sessions altogether.).

Class Method Details

# File 'lib/pry/pry_class.rb', line 299defself.auto_resize!Pry.config.input# by default, load Readlineif!defined?(Readline)||Pry.config.input!=Readlinewarn"Sorry, you must be using Readline for Pry.auto_resize! to work."returnendifReadline::VERSION=~/edit/iwarn"Readline version \#{Readline::VERSION} detected - will not auto_resize! correctly.\nFor the fix, use GNU Readline instead:\nhttps://github.com/guard/guard/wiki/Add-proper-Readline-support-to-Ruby-on-Mac-OS-X\n"returnendtrap:WINCHdobeginReadline.set_screen_size(*Terminal.size!)rescue=>ewarn"\nPry.auto_resize!'s Readline.set_screen_size failed: #{e}"endbeginReadline.refresh_linerescue=>ewarn"\nPry.auto_resize!'s Readline.refresh_line failed: #{e}"endendend

.binding_for(target) ⇒ Binding

Return a Binding object for target or return target if it is
already a Binding.
In the case where target is top-level then return TOPLEVEL_BINDING

# File 'lib/pry/pry_class.rb', line 135defself.initial_session_setupreturnunlessinitial_session?@initial_session=false# note these have to be loaded here rather than in pry_instance as# we only want them loaded once per entire Pry lifetime.load_rc_filesend

# File 'lib/pry/pry_class.rb', line 116defself.load_win32consolebeginrequire'win32console'# The mswin and mingw versions of pry require win32console, so this should# only fail on jruby (where win32console doesn't work).# Instead we'll recommend ansicon, which does.rescueLoadErrorwarn"For a better Pry experience on Windows, please use ansicon:\nhttps://github.com/adoxa/ansicon\nIf you use an alternative to ansicon and don't want to see this warning again,\nyou can add \"Pry.config.windows_console_warning = false\" to your .pryrc.\n"ifPry.config.windows_console_warningendend

# File 'lib/pry/pry_class.rb', line 162defself.start(target=nil,options={})returnifENV['DISABLE_PRY']ifENV['FAIL_PRY']raise'You have FAIL_PRY set to true, which results in Pry calls failing'endoptions=options.to_hashifin_critical_section?output.puts"ERROR: Pry started inside Pry."output.puts"This can happen if you have a binding.pry inside a #to_s or #inspect function."returnendoptions[:target]=Pry.binding_for(target||toplevel_binding)initial_session_setupfinal_session_setup# Unless we were given a backtrace, save the current oneifoptions[:backtrace].nil?options[:backtrace]=caller# If Pry was started via `binding.pry`, elide that from the backtraceifoptions[:backtrace].first=~/pry.*core_extensions.*pry/options[:backtrace].shiftendenddriver=options[:driver]||Pry::REPL# Enter the matrixdriver.start(options)rescuePry::TooSafeExceptionputs"ERROR: Pry cannot work with $SAFE > 0"raiseend

# File 'lib/pry/pry_class.rb', line 366defself.toplevel_bindingunlessdefined?(@toplevel_binding)&&@toplevel_binding# Grab a copy of the TOPLEVEL_BINDING without any local variables.# This binding has a default definee of Object, and new methods are# private (just as in TOPLEVEL_BINDING).TOPLEVEL_BINDING.eval"def self.__pry__\nbinding\nend\nPry.toplevel_binding = __pry__\nclass << self; undef __pry__; end\n"end@toplevel_binding.eval('private')@toplevel_bindingend

# File 'lib/pry/pry_class.rb', line 224defself.view_clip(obj,options={})max=options.fetch:max_length,60id=options.fetch:id,falseifobj.kind_of?(Module)&&obj.name.to_s!=""&&obj.name.to_s.length<=maxobj.name.to_selsifPry.main==obj# special-case to support jruby.# fixed as of https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039# we can drop in the future.obj.to_selsifPry.config.prompt_safe_objects.any?{|v|v===obj}&&obj.inspect.length<=maxobj.inspectelseid==true?"#<#{obj.class}:0x%x>"%(obj.object_id<<1):"#<#{obj.class}>"endrescueRescuableException"unknown"end

#eval(line, options = {}) ⇒ Boolean

Pass a line of input to Pry.

This is the equivalent of Binding#eval but with extra Pry!

In particular:
1. Pry commands will be executed immediately if the line matches.
2. Partial lines of input will be queued up until a complete expression has
been accepted.
3. Output is written to #output in pretty colours, not returned.

Once this method has raised an exception or returned false, this instance
is no longer usable. #exit_value will return the session's breakout
value if applicable.

Parameters:

line(String?)
—

The line of input; nil if the user types <Ctrl-D>

options(Hash)(defaults to: {})
—

a customizable set of options

Options Hash (options):

:generated(Boolean)
—

Whether this line was generated automatically.
Generated lines are not stored in history.

Returns:

(Boolean)
—

Is Pry ready to accept more input?

Raises:

(Exception)
—

If the user uses the raise-up command, this method
will raise that exception.

# File 'lib/pry/pry_instance.rb', line 237defeval(line,options={})returnfalseif@stoppedexit_value=nilexception=catch(:raise_up)doexit_value=catch(:breakout)dohandle_line(line,options)# We use 'return !@stopped' here instead of 'return true' so that if# handle_line has stopped this pry instance (e.g. by opening _pry_.repl and# then popping all the bindings) we still exit immediately.return!@stoppedendexception=falseend@stopped=true@exit_value=exit_value# TODO: make this configurable?raiseexceptionifexceptionreturnfalseend

# File 'lib/pry/pry_instance.rb', line 260defhandle_line(line,options)ifline.nil?config.control_d_handler.call(@eval_string,self)returnendensure_correct_encoding!(line)Pry.history<<lineunlessoptions[:generated]@suppress_output=falseinject_sticky_locals!beginif!process_command_safely(line)@eval_string<<"#{line.chomp}\n"if!line.empty?||!@eval_string.empty?endrescueRescuableException=>eself.last_exception=eresult=ePry.critical_sectiondoshow_result(result)endreturnend# This hook is supposed to be executed after each line of ruby code# has been read (regardless of whether eval_string is yet a complete expression)exec_hook:after_read,eval_string,selfbegincomplete_expr=Pry::Code.complete_expression?(@eval_string)rescueSyntaxError=>eoutput.puts"SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}"reset_eval_stringendifcomplete_exprif@eval_string=~/;\Z/||@eval_string.empty?||@eval_string=~/\A *#.*\n\z/@suppress_output=trueend# A bug in jruby makes java.lang.Exception not rescued by# `rescue Pry::RescuableException` clause.## * https://github.com/pry/pry/issues/854# * https://jira.codehaus.org/browse/JRUBY-7100## Until that gets fixed upstream, treat java.lang.Exception# as an additional exception to be rescued explicitly.## This workaround has a side effect: java exceptions specified# in `Pry.config.exception_whitelist` are ignored.jruby_exceptions=[]ifPry::Helpers::BaseHelpers.jruby?jruby_exceptions<<Java::JavaLang::Exceptionendbegin# Reset eval string, in case we're evaluating Ruby that does something# like open a nested REPL on this instance.eval_string=@eval_stringreset_eval_stringresult=evaluate_ruby(eval_string)rescueRescuableException,*jruby_exceptions=>e# Eliminate following warning:# warning: singleton on non-persistent Java type X# (http://wiki.jruby.org/Persistence)ifPry::Helpers::BaseHelpers.jruby?&&e.class.respond_to?('__persistent__')e.class.__persistent__=trueendself.last_exception=eresult=eendPry.critical_sectiondoshow_result(result)endendthrow(:breakout)ifcurrent_binding.nil?end

# File 'lib/pry/pry_instance.rb', line 402defprocess_command(val)val=val.lstripif/^\s\S/!~valval=val.chompresult=commands.process_line(val,:target=>current_binding,:output=>output,:eval_string=>@eval_string,:pry_instance=>self,:hooks=>hooks)# set a temporary (just so we can inject the value we want into eval_string)Pry.current[:pry_cmd_result]=result# note that `result` wraps the result of command processing; if a# command was matched and invoked then `result.command?` returns true,# otherwise it returns false.ifresult.command?if!result.void_command?# the command that was invoked was non-void (had a return value) and so we make# the value of the current expression equal to the return value# of the command.@eval_string.replace"::Pry.current[:pry_cmd_result].retval\n"endtrueelsefalseendend

#process_command_safely(val) ⇒ Boolean

Same as process_command, but outputs exceptions to #output instead of
raising.

Potentially deprecated — Use Pry::REPL.new(pry, :target => target).start
(If nested sessions are going to exist, this method is fine, but a goal is
to come up with an alternative to nested sessions altogether.)

# File 'lib/pry/pry_instance.rb', line 363defshow_result(result)iflast_result_is_exception?exception_handler.call(output,result,self)elsifshould_print?print.call(output,result,self)else# nothin'endrescueRescuableException=>e# Being uber-paranoid here, given that this exception arose because we couldn't# serialize something in the user's program, let's not assume we can serialize# the exception either.beginoutput.puts"(pry) output error: #{e.inspect}\n#{e.backtrace.join("\n")}"rescueRescuableException=>eiflast_result_is_exception?output.puts"(pry) output error: failed to show exception"elseoutput.puts"(pry) output error: failed to show result"endendensureoutput.flushifoutput.respond_to?(:flush)end

Update Pry's internal state after evalling code.
This method should not need to be invoked directly.

Parameters:

code(String)
—

The code we just eval'd

505
506
507
508
509
510
511
512

# File 'lib/pry/pry_instance.rb', line 505defupdate_input_history(code)# Always push to the @input_array as the @output_array is always pushed to.@input_array<<codeifcodePry.line_buffer.push(*code.each_line)Pry.current_line+=code.lines.countendend