1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00
pry--pry/lib/pry/command_context.rb
John Mair a04e56012a made it so commands (with :keep_retval => true) can now return nil as a legitimate return value. Created a new 'void' value to use instead when indicating no return value. also updated tests.
'void' method now available to commands, commands must return this when they do not want their result displayed when they use :keep_retval => true. void just maps to a random object Pry::CommandContext::VOID_VALUE.
2011-09-04 13:30:20 +12:00

48 lines
1.2 KiB
Ruby

class Pry
# Command contexts are the objects runing each command.
# Helper modules can be mixed into this class.
class CommandContext
# represents a void return value for a command
VOID_VALUE = Object.new
# give it a nice inspect
def VOID_VALUE.inspect() "void" end
attr_accessor :output
attr_accessor :target
attr_accessor :captures
attr_accessor :eval_string
attr_accessor :arg_string
attr_accessor :opts
attr_accessor :command_set
attr_accessor :command_processor
attr_accessor :void
attr_accessor :_pry_
# Run a command from another command.
# @param [String] command_string The string that invokes the command
# @param [Array] args Further arguments to pass to the command
# @example
# run "show-input"
# @example
# run ".ls"
# @example
# run "amend-line", "5", 'puts "hello world"'
def run(command_string, *args)
complete_string = "#{command_string} #{args.join(" ")}"
command_processor.process_commands(complete_string, eval_string, target)
end
def commands
command_set.commands
end
def text
Pry::Helpers::Text
end
include Pry::Helpers::BaseHelpers
include Pry::Helpers::CommandHelpers
end
end