A class that wraps the current state of the irb session, including the configuration of IRB.conf.
- #
- C
- E
- F
- H
- I
- M
- N
- P
- R
- S
- U
- V
- W
Attributes
[RW] | ap_name | A copy of the default |
[RW] | auto_indent_mode | Can be either the default To disable auto-indentation in irb:
or
or
See Configuration at |
[RW] | back_trace_limit | The limit of backtrace lines displayed as top The default value is 16. Can also be set using the |
[RW] | command_aliases | User-defined |
[RW] | echo | Whether to echo the return value to output or not. Uses
|
[RW] | echo? | Whether to echo the return value to output or not. Uses
|
[RW] | echo_on_assignment | Whether to echo for assignment expressions. If set to If set to If set to It defaults to
To set the behaviour of showing on assignment in irb:
or
or
|
[RW] | echo_on_assignment? | Whether to echo for assignment expressions. If set to If set to If set to It defaults to
To set the behaviour of showing on assignment in irb:
or
or
|
[R] | eval_history | The command result history limit. This method is not available until |
[RW] | extra_doc_dirs | Specify the installation locations of the ri file to be displayed in the document dialog. |
[RW] | ignore_eof | Whether If set to |
[RW] | ignore_eof? | Whether If set to |
[RW] | ignore_sigint | Whether If set to If set to
|
[RW] | ignore_sigint? | Whether If set to If set to
|
[R] | inspect_mode | A copy of the default |
[RW] | io | The current input method. Can be either |
[RW] | irb | Current irb session. |
[RW] | irb_name | Can be either name from |
[R] | irb_path | Can be one of the following:
|
[R] | last_value | The return value of the last statement evaluated. |
[RW] | load_modules | A copy of the default |
[RW] | newline_before_multiline_output | Whether a newline is put before multiline output. Uses
|
[RW] | newline_before_multiline_output? | Whether a newline is put before multiline output. Uses
|
[RW] | prompt_c |
See Custom Prompts for more information. |
[RW] | prompt_i | Standard See Custom Prompts for more information. |
[R] | prompt_mode | A copy of the default |
[RW] | prompt_s |
See Custom Prompts for more information. |
[RW] | rc | A copy of the default |
[RW] | rc? | A copy of the default |
[RW] | return_format | The format of the return statement, set by |
[R] | thread | The current thread in this context. |
[R] | use_autocomplete | Whether colorization is enabled or not. A copy of the default |
[R] | use_autocomplete? | Whether colorization is enabled or not. A copy of the default |
[R] | use_multiline | Whether multiline editor mode is enabled or not. A copy of the default |
[R] | use_multiline? | Whether multiline editor mode is enabled or not. A copy of the default |
[R] | use_readline | Whether singleline editor mode is enabled or not. A copy of the default |
[R] | use_readline? | Whether singleline editor mode is enabled or not. A copy of the default |
[R] | use_reline | Whether multiline editor mode is enabled or not. A copy of the default |
[R] | use_reline? | Whether multiline editor mode is enabled or not. A copy of the default |
[R] | use_singleline | Whether singleline editor mode is enabled or not. A copy of the default |
[R] | use_singleline? | Whether singleline editor mode is enabled or not. A copy of the default |
[RW] | verbose | Whether verbose messages are displayed or not. A copy of the default |
[RW] | with_debugger | |
[R] | workspace_home | The toplevel workspace, see |
Class Public methods
new(irb, workspace = nil, input_method = nil) Link
Creates a new IRB
context.
The optional input_method
argument:
nil
String
-
uses a
File
other
-
uses this as
InputMethod
# File ruby/lib/irb/context.rb, line 23 def initialize(irb, workspace = nil, input_method = nil) @irb = irb @workspace_stack = [] if workspace @workspace_stack << workspace else @workspace_stack << WorkSpace.new end @thread = Thread.current # copy of default configuration @ap_name = IRB.conf[:AP_NAME] @rc = IRB.conf[:RC] @load_modules = IRB.conf[:LOAD_MODULES] if IRB.conf.has_key?(:USE_SINGLELINE) @use_singleline = IRB.conf[:USE_SINGLELINE] elsif IRB.conf.has_key?(:USE_READLINE) # backward compatibility @use_singleline = IRB.conf[:USE_READLINE] else @use_singleline = nil end if IRB.conf.has_key?(:USE_MULTILINE) @use_multiline = IRB.conf[:USE_MULTILINE] elsif IRB.conf.has_key?(:USE_RELINE) # backward compatibility warn <<~MSG.strip USE_RELINE is deprecated, please use USE_MULTILINE instead. MSG @use_multiline = IRB.conf[:USE_RELINE] elsif IRB.conf.has_key?(:USE_REIDLINE) warn <<~MSG.strip USE_REIDLINE is deprecated, please use USE_MULTILINE instead. MSG @use_multiline = IRB.conf[:USE_REIDLINE] else @use_multiline = nil end @use_autocomplete = IRB.conf[:USE_AUTOCOMPLETE] @verbose = IRB.conf[:VERBOSE] @io = nil self.inspect_mode = IRB.conf[:INSPECT_MODE] self.use_tracer = IRB.conf[:USE_TRACER] self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER] self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY] @ignore_sigint = IRB.conf[:IGNORE_SIGINT] @ignore_eof = IRB.conf[:IGNORE_EOF] @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT] self.prompt_mode = IRB.conf[:PROMPT_MODE] if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager) @irb_name = IRB.conf[:IRB_NAME] else @irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s end self.irb_path = "(" + @irb_name + ")" case input_method when nil @io = nil case use_multiline? when nil if term_interactive? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline? # Both of multiline mode and singleline mode aren't specified. @io = RelineInputMethod.new(build_completor) else @io = nil end when false @io = nil when true @io = RelineInputMethod.new(build_completor) end unless @io case use_singleline? when nil if (defined?(ReadlineInputMethod) && term_interactive? && IRB.conf[:PROMPT_MODE] != :INF_RUBY) @io = ReadlineInputMethod.new else @io = nil end when false @io = nil when true if defined?(ReadlineInputMethod) @io = ReadlineInputMethod.new else @io = nil end else @io = nil end end @io = StdioInputMethod.new unless @io when '-' @io = FileInputMethod.new($stdin) @irb_name = '-' self.irb_path = '-' when String @io = FileInputMethod.new(input_method) @irb_name = File.basename(input_method) self.irb_path = input_method else @io = input_method end @extra_doc_dirs = IRB.conf[:EXTRA_DOC_DIRS] @echo = IRB.conf[:ECHO] if @echo.nil? @echo = true end @echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT] if @echo_on_assignment.nil? @echo_on_assignment = :truncate end @newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT] if @newline_before_multiline_output.nil? @newline_before_multiline_output = true end @user_aliases = IRB.conf[:COMMAND_ALIASES].dup @command_aliases = @user_aliases.merge(KEYWORD_ALIASES) end
Instance Public methods
change_workspace(*_main) Link
Changes the current workspace to given object or binding.
If the optional argument is omitted, the workspace will be home_workspace
which is inherited from TOPLEVEL_BINDING
or the main object, IRB.conf[:MAIN_CONTEXT]
when irb was initialized.
See IRB::WorkSpace.new
for more information.
eval_history=(val) Link
file_input?() Link
from_binding?() Link
history_file() Link
A copy of the default IRB.conf[:HISTORY_FILE]
home_workspace() Link
Inherited from TOPLEVEL_BINDING
.
inspect?() Link
Whether inspect_mode
is set or not, see inspect_mode=
for more detail.
inspect_mode=(opt) Link
Specifies the inspect mode with opt
:
true
-
display
inspect
false
-
display
to_s
nil
-
inspect mode in non-math mode, non-inspect mode in math mode
See IRB::Inspector
for more information.
Can also be set using the --inspect
and --noinspect
command line options.
# File ruby/lib/irb/context.rb, line 550 def inspect_mode=(opt) if i = Inspector::INSPECTORS[opt] @inspect_mode = opt @inspect_method = i i.init else case opt when nil if Inspector.keys_with_inspector(Inspector::INSPECTORS[true]).include?(@inspect_mode) self.inspect_mode = false elsif Inspector.keys_with_inspector(Inspector::INSPECTORS[false]).include?(@inspect_mode) self.inspect_mode = true else puts "Can't switch inspect mode." return end when /^\s*\{.*\}\s*$/ begin inspector = eval "proc#{opt}" rescue Exception puts "Can't switch inspect mode(#{opt})." return end self.inspect_mode = inspector when Proc self.inspect_mode = IRB::Inspector(opt) when Inspector prefix = "usr%d" i = 1 while Inspector::INSPECTORS[format(prefix, i)]; i += 1; end @inspect_mode = format(prefix, i) @inspect_method = opt Inspector.def_inspector(format(prefix, i), @inspect_method) else puts "Can't switch inspect mode(#{opt})." return end end print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose? @inspect_mode end
irb_path=(path) Link
Sets @irb_path to the given path
as well as @eval_path @eval_path is used for evaluating code in the context of IRB
session It’s the same as irb_path
, but with the IRB
name postfix This makes sure users can distinguish the methods defined in the IRB
session from the methods defined in the current file’s context, especially with binding.irb
main() Link
The top-level workspace, see WorkSpace#main
pop_workspace() Link
Removes the last element from the current workspaces stack and returns it, or nil
if the current workspace stack is empty.
Also, see push_workspace
.
prompt_mode=(mode) Link
Sets the mode
of the prompt in this context.
See Custom Prompts for more information.
# File ruby/lib/irb/context.rb, line 513 def prompt_mode=(mode) @prompt_mode = mode pconf = IRB.conf[:PROMPT][mode] @prompt_i = pconf[:PROMPT_I] @prompt_s = pconf[:PROMPT_S] @prompt_c = pconf[:PROMPT_C] @return_format = pconf[:RETURN] @return_format = "%s\n" if @return_format == nil if ai = pconf.include?(:AUTO_INDENT) @auto_indent_mode = ai else @auto_indent_mode = IRB.conf[:AUTO_INDENT] end end
prompt_n() Link
TODO: Remove this when developing v2.0
prompt_n=(_) Link
TODO: Remove this when developing v2.0
prompting?() Link
Whether verbose?
is true
, and input_method
is either StdioInputMethod
or RelineInputMethod
or ReadlineInputMethod
, see io
for more information.
push_workspace(*_main) Link
Creates a new workspace with the given object or binding, and appends it onto the current workspaces stack.
See IRB::Context#change_workspace
and IRB::WorkSpace.new
for more information.
# File ruby/lib/irb/ext/workspaces.rb, line 14 def push_workspace(*_main) if _main.empty? if @workspace_stack.size > 1 # swap the top two workspaces previous_workspace, current_workspace = @workspace_stack.pop(2) @workspace_stack.push current_workspace, previous_workspace end else new_workspace = WorkSpace.new(workspace.binding, _main[0]) @workspace_stack.push new_workspace new_workspace.load_helper_methods_to_main end end
replace_workspace(workspace) Link
Replace the current workspace with the given workspace
.
save_history() Link
save_history=(val) Link
set_last_value(value) Link
Sets the return value from the last statement evaluated in this context to last_value
.
use_loader() Link
Returns whether irb
‘s own file reader method is used by load
/require
or not.
This mode is globally affected (irb-wide).
use_loader=(val) Link
use_tracer=(val) Link
verbose?() Link
Returns whether messages are displayed or not.
# File ruby/lib/irb/context.rb, line 477 def verbose? if @verbose.nil? if @io.kind_of?(RelineInputMethod) false elsif defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod) false elsif !STDIN.tty? or @io.kind_of?(FileInputMethod) true else false end else @verbose end end