Class: IRB::Context
- Defined in:
- lib/irb/context.rb,
lib/irb/ext/change-ws.rb,
lib/irb/ext/use-loader.rb,
lib/irb/ext/workspaces.rb,
lib/irb/ext/eval_history.rb
Overview
:nodoc:
Constant Summary collapse
- ASSIGN_OPERATORS_REGEXP =
Regexp.union(%w[= += -= *= /= %= **= &= |= &&= ||= ^= <<= >>=])
- NOPRINTING_IVARS =
:nodoc:
["@last_value"]
- NO_INSPECTING_IVARS =
:nodoc:
["@irb", "@io"]
- IDNAME_IVARS =
:nodoc:
["@prompt_mode"]
Instance Attribute Summary collapse
-
#ap_name ⇒ Object
A copy of the default
IRB.conf[:AP_NAME]
. -
#auto_indent_mode ⇒ Object
Can be either the default
IRB.conf[:AUTO_INDENT]
, or the mode set by #prompt_mode=. -
#back_trace_limit ⇒ Object
The limit of backtrace lines displayed as top
n
and tailn
. -
#command_aliases ⇒ Object
User-defined IRB command aliases.
-
#echo ⇒ Object
(also: #echo?)
Whether to echo the return value to output or not.
-
#echo_on_assignment ⇒ Object
(also: #echo_on_assignment?)
Whether to echo for assignment expressions.
-
#eval_history ⇒ Object
The command result history limit.
-
#extra_doc_dirs ⇒ Object
Specify the installation locations of the ri file to be displayed in the document dialog.
-
#ignore_eof ⇒ Object
(also: #ignore_eof?)
Whether
^D
(control-d
) will be ignored or not. -
#ignore_sigint ⇒ Object
(also: #ignore_sigint?)
Whether
^C
(control-c
) will be ignored or not. -
#inspect_mode ⇒ Object
A copy of the default
IRB.conf[:INSPECT_MODE]
. -
#io ⇒ Object
The current input method.
-
#irb ⇒ Object
Current irb session.
-
#irb_name ⇒ Object
Can be either name from
IRB.conf[:IRB_NAME]
, or the number of the current job set by JobManager, such asirb#2
. -
#irb_path ⇒ Object
Can be one of the following: - the #irb_name surrounded by parenthesis - the
input_method
passed to Context.new - the file path of the current IRB context in a binding.irb session. -
#last_value ⇒ Object
readonly
The return value of the last statement evaluated.
-
#load_modules ⇒ Object
A copy of the default
IRB.conf[:LOAD_MODULES]
. -
#newline_before_multiline_output ⇒ Object
(also: #newline_before_multiline_output?)
Whether a newline is put before multiline output.
-
#prompt_c ⇒ Object
IRB prompt for continuated statement.
-
#prompt_i ⇒ Object
Standard IRB prompt.
-
#prompt_mode ⇒ Object
A copy of the default
IRB.conf[:PROMPT_MODE]
. -
#prompt_s ⇒ Object
IRB prompt for continuated strings.
-
#rc ⇒ Object
(also: #rc?)
A copy of the default
IRB.conf[:RC]
. -
#return_format ⇒ Object
The format of the return statement, set by #prompt_mode= using the
:RETURN
of themode
passed to set the current #prompt_mode. -
#thread ⇒ Object
readonly
The current thread in this context.
-
#use_autocomplete ⇒ Object
(also: #use_autocomplete?)
readonly
Whether colorization is enabled or not.
-
#use_multiline ⇒ Object
(also: #use_multiline?, #use_reline, #use_reline?)
readonly
Whether multiline editor mode is enabled or not.
-
#use_singleline ⇒ Object
(also: #use_singleline?, #use_readline, #use_readline?)
readonly
Whether singleline editor mode is enabled or not.
-
#verbose ⇒ Object
Whether verbose messages are displayed or not.
-
#with_debugger ⇒ Object
Returns the value of attribute with_debugger.
-
#workspace_home ⇒ Object
readonly
The toplevel workspace, see #home_workspace.
Instance Method Summary collapse
- #__inspect__ ⇒ Object
-
#_set_last_value ⇒ Object
Sets the return value from the last statement evaluated in this context to #last_value.
-
#change_workspace(*_main) ⇒ Object
Changes the current workspace to given object or binding.
- #colorize_input(input, complete:) ⇒ Object
-
#evaluate(statement, line_no) ⇒ Object
:nodoc:.
-
#evaluate_expression(code, line_no) ⇒ Object
:nodoc:.
-
#file_input? ⇒ Boolean
Whether #io uses a File for the
input_method
passed when creating the current context, see ::new. - #from_binding? ⇒ Boolean
-
#history_file ⇒ Object
A copy of the default
IRB.conf[:HISTORY_FILE]
. -
#history_file=(hist) ⇒ Object
Set
IRB.conf[:HISTORY_FILE]
to the givenhist
. -
#home_workspace ⇒ Object
Inherited from
TOPLEVEL_BINDING
. -
#initialize(irb, workspace = nil, input_method = nil) ⇒ Context
constructor
Creates a new IRB context.
-
#inspect ⇒ Object
(also: #to_s)
:nodoc:.
-
#inspect? ⇒ Boolean
Whether #inspect_mode is set or not, see #inspect_mode= for more detail.
-
#inspect_last_value ⇒ Object
:nodoc:.
-
#local_variables ⇒ Object
:nodoc:.
-
#main ⇒ Object
The top-level workspace, see WorkSpace#main.
- #parse_command(code) ⇒ Object
-
#pop_workspace ⇒ Object
Removes the last element from the current #workspaces stack and returns it, or
nil
if the current workspace stack is empty. -
#prompt_n ⇒ Object
TODO: Remove this when developing v2.0.
-
#prompt_n=(_) ⇒ Object
TODO: Remove this when developing v2.0.
-
#prompting? ⇒ Boolean
Whether #verbose? is
true
, andinput_method
is either StdioInputMethod or RelineInputMethod or ReadlineInputMethod, see #io for more information. -
#push_workspace(*_main) ⇒ Object
Creates a new workspace with the given object or binding, and appends it onto the current #workspaces stack.
-
#replace_workspace(workspace) ⇒ Object
Replace the current workspace with the given
workspace
. - #save_history ⇒ Object
- #save_history=(val) ⇒ Object
-
#set_last_value(value) ⇒ Object
Sets the return value from the last statement evaluated in this context to #last_value.
-
#use_loader ⇒ Object
(also: #use_loader?)
Returns whether
irb
‘s own file reader method is used byload
/require
or not. -
#use_loader=(opt) ⇒ Object
Sets
IRB.conf[:USE_LOADER]
. - #use_tracer=(val) ⇒ Object
-
#verbose? ⇒ Boolean
Returns whether messages are displayed or not.
-
#workspace ⇒ Object
Workspace in the current context.
Constructor Details
#initialize(irb, workspace = nil, input_method = nil) ⇒ Context
Creates a new IRB context.
The optional input_method
argument:
nil
-
uses stdin or Reline or Readline
String
-
uses a File
other
-
uses this as InputMethod
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/irb/context.rb', line 24 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] @irb_name = IRB.conf[:IRB_NAME] unless IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager) @irb_name = @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 @command_aliases = IRB.conf[:COMMAND_ALIASES].dup end |
Instance Attribute Details
#ap_name ⇒ Object
A copy of the default IRB.conf[:AP_NAME]
258 259 260 |
# File 'lib/irb/context.rb', line 258 def ap_name @ap_name end |
#auto_indent_mode ⇒ Object
346 347 348 |
# File 'lib/irb/context.rb', line 346 def auto_indent_mode @auto_indent_mode end |
#back_trace_limit ⇒ Object
The limit of backtrace lines displayed as top n
and tail n
.
The default value is 16.
Can also be set using the --back-trace-limit
command line option.
437 438 439 |
# File 'lib/irb/context.rb', line 437 def back_trace_limit @back_trace_limit end |
#command_aliases ⇒ Object
User-defined IRB command aliases
440 441 442 |
# File 'lib/irb/context.rb', line 440 def command_aliases @command_aliases end |
#echo ⇒ Object Also known as: echo?
Whether to echo the return value to output or not.
Uses IRB.conf[:ECHO]
if available, or defaults to true
.
puts "hello"
# hello
#=> nil
IRB.CurrentContext.echo = false
puts "omg"
# omg
377 378 379 |
# File 'lib/irb/context.rb', line 377 def echo @echo end |
#echo_on_assignment ⇒ Object Also known as: echo_on_assignment?
Whether to echo for assignment expressions.
If set to false
, the value of assignment will not be shown.
If set to true
, the value of assignment will be shown.
If set to :truncate
, the value of assignment will be shown and truncated.
It defaults to :truncate
.
a = "omg"
#=> omg
a = "omg" * 10
#=> omgomgomgomgomgomgomg...
IRB.CurrentContext.echo_on_assignment = false
a = "omg"
IRB.CurrentContext.echo_on_assignment = true
a = "omg" * 10
#=> omgomgomgomgomgomgomgomgomgomg
To set the behaviour of showing on assignment in irb:
IRB.conf[:ECHO_ON_ASSIGNMENT] = :truncate or true or false
or
irb_context.echo_on_assignment = :truncate or true or false
or
IRB.CurrentContext.echo_on_assignment = :truncate or true or false
412 413 414 |
# File 'lib/irb/context.rb', line 412 def echo_on_assignment @echo_on_assignment end |
#eval_history ⇒ Object
The command result history limit. This method is not available until #eval_history= was called with non-nil value (directly or via setting IRB.conf[:EVAL_HISTORY]
in .irbrc
).
31 32 33 |
# File 'lib/irb/ext/eval_history.rb', line 31 def eval_history @eval_history end |
#extra_doc_dirs ⇒ Object
Specify the installation locations of the ri file to be displayed in the document dialog.
366 367 368 |
# File 'lib/irb/context.rb', line 366 def extra_doc_dirs @extra_doc_dirs end |
#ignore_eof ⇒ Object Also known as: ignore_eof?
Whether ^D
(control-d
) will be ignored or not.
If set to false
, ^D
will quit irb.
363 364 365 |
# File 'lib/irb/context.rb', line 363 def ignore_eof @ignore_eof end |
#ignore_sigint ⇒ Object Also known as: ignore_sigint?
Whether ^C
(control-c
) will be ignored or not.
If set to false
, ^C
will quit irb.
If set to true
,
-
during input: cancel input then return to top level.
-
during execute: abandon current execution.
359 360 361 |
# File 'lib/irb/context.rb', line 359 def ignore_sigint @ignore_sigint end |
#inspect_mode ⇒ Object
A copy of the default IRB.conf[:INSPECT_MODE]
301 302 303 |
# File 'lib/irb/context.rb', line 301 def inspect_mode @inspect_mode end |
#io ⇒ Object
The current input method.
Can be either StdioInputMethod, ReadlineInputMethod, RelineInputMethod, FileInputMethod or other specified when the context is created. See ::new for more # information on input_method
.
253 254 255 |
# File 'lib/irb/context.rb', line 253 def io @io end |
#irb ⇒ Object
Current irb session.
256 257 258 |
# File 'lib/irb/context.rb', line 256 def irb @irb end |
#irb_name ⇒ Object
Can be either name from IRB.conf[:IRB_NAME]
, or the number of the current job set by JobManager, such as irb#2
265 266 267 |
# File 'lib/irb/context.rb', line 265 def irb_name @irb_name end |
#irb_path ⇒ Object
Can be one of the following:
-
the #irb_name surrounded by parenthesis
-
the
input_method
passed to Context.new -
the file path of the current IRB context in a binding.irb session
271 272 273 |
# File 'lib/irb/context.rb', line 271 def irb_path @irb_path end |
#last_value ⇒ Object (readonly)
The return value of the last statement evaluated.
491 492 493 |
# File 'lib/irb/context.rb', line 491 def last_value @last_value end |
#load_modules ⇒ Object
A copy of the default IRB.conf[:LOAD_MODULES]
262 263 264 |
# File 'lib/irb/context.rb', line 262 def load_modules @load_modules end |
#newline_before_multiline_output ⇒ Object Also known as: newline_before_multiline_output?
Whether a newline is put before multiline output.
Uses IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
if available, or defaults to true
.
"abc\ndef"
#=>
abc
def
IRB.CurrentContext.newline_before_multiline_output = false
"abc\ndef"
#=> abc
def
426 427 428 |
# File 'lib/irb/context.rb', line 426 def newline_before_multiline_output @newline_before_multiline_output end |
#prompt_c ⇒ Object
IRB prompt for continuated statement. (e.g. immediately after an if
)
See Custom Prompts for more information.
316 317 318 |
# File 'lib/irb/context.rb', line 316 def prompt_c @prompt_c end |
#prompt_i ⇒ Object
Standard IRB prompt.
See Custom Prompts for more information.
308 309 310 |
# File 'lib/irb/context.rb', line 308 def prompt_i @prompt_i end |
#prompt_mode ⇒ Object
A copy of the default IRB.conf[:PROMPT_MODE]
304 305 306 |
# File 'lib/irb/context.rb', line 304 def prompt_mode @prompt_mode end |
#prompt_s ⇒ Object
IRB prompt for continuated strings.
See Custom Prompts for more information.
312 313 314 |
# File 'lib/irb/context.rb', line 312 def prompt_s @prompt_s end |
#rc ⇒ Object Also known as: rc?
A copy of the default IRB.conf[:RC]
260 261 262 |
# File 'lib/irb/context.rb', line 260 def rc @rc end |
#return_format ⇒ Object
The format of the return statement, set by #prompt_mode= using the :RETURN
of the mode
passed to set the current #prompt_mode.
349 350 351 |
# File 'lib/irb/context.rb', line 349 def return_format @return_format end |
#thread ⇒ Object (readonly)
The current thread in this context.
247 248 249 |
# File 'lib/irb/context.rb', line 247 def thread @thread end |
#use_autocomplete ⇒ Object (readonly) Also known as: use_autocomplete?
Whether colorization is enabled or not.
A copy of the default IRB.conf[:USE_AUTOCOMPLETE]
299 300 301 |
# File 'lib/irb/context.rb', line 299 def use_autocomplete @use_autocomplete end |
#use_multiline ⇒ Object (readonly) Also known as: use_multiline?, use_reline, use_reline?
Whether multiline editor mode is enabled or not.
A copy of the default IRB.conf[:USE_MULTILINE]
291 292 293 |
# File 'lib/irb/context.rb', line 291 def use_multiline @use_multiline end |
#use_singleline ⇒ Object (readonly) Also known as: use_singleline?, use_readline, use_readline?
Whether singleline editor mode is enabled or not.
A copy of the default IRB.conf[:USE_SINGLELINE]
295 296 297 |
# File 'lib/irb/context.rb', line 295 def use_singleline @use_singleline end |
#verbose ⇒ Object
Whether verbose messages are displayed or not.
A copy of the default IRB.conf[:VERBOSE]
430 431 432 |
# File 'lib/irb/context.rb', line 430 def verbose @verbose end |
#with_debugger ⇒ Object
Returns the value of attribute with_debugger.
442 443 444 |
# File 'lib/irb/context.rb', line 442 def with_debugger @with_debugger end |
#workspace_home ⇒ Object (readonly)
The toplevel workspace, see #home_workspace
245 246 247 |
# File 'lib/irb/context.rb', line 245 def workspace_home @workspace_home end |
Instance Method Details
#__inspect__ ⇒ Object
675 |
# File 'lib/irb/context.rb', line 675 alias __inspect__ inspect |
#_set_last_value ⇒ Object
Sets the return value from the last statement evaluated in this context to #last_value. See #set_last_value
14 15 16 17 |
# File 'lib/irb/ext/eval_history.rb', line 14 def set_last_value(value) @last_value = value workspace.local_variable_set :_, value end |
#change_workspace(*_main) ⇒ Object
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.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/irb/ext/change-ws.rb', line 26 def change_workspace(*_main) if _main.empty? replace_workspace(home_workspace) return main end workspace = WorkSpace.new(_main[0]) replace_workspace(workspace) workspace.load_helper_methods_to_main end |
#colorize_input(input, complete:) ⇒ Object
652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'lib/irb/context.rb', line 652 def colorize_input(input, complete:) if IRB.conf[:USE_COLORIZE] && IRB::Color.colorable? lvars = local_variables || [] if parse_command(input) name, sep, arg = input.split(/(\s+)/, 2) arg = IRB::Color.colorize_code(arg, complete: complete, local_variables: lvars) "#{IRB::Color.colorize(name, [:BOLD])}\e[m#{sep}#{arg}" else IRB::Color.colorize_code(input, complete: complete, local_variables: lvars) end else Reline::Unicode.escape_for_print(input) end end |
#evaluate(statement, line_no) ⇒ Object
:nodoc:
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/irb/context.rb', line 583 def evaluate(statement, line_no) # :nodoc: @line_no = line_no case statement when Statement::EmptyInput return when Statement::Expression result = evaluate_expression(statement.code, line_no) set_last_value(result) when Statement::Command statement.command_class.execute(self, statement.arg) end nil end |
#evaluate_expression(code, line_no) ⇒ Object
:nodoc:
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/irb/context.rb', line 603 def evaluate_expression(code, line_no) # :nodoc: result = nil if IRB.conf[:MEASURE] && IRB.conf[:MEASURE_CALLBACKS].empty? IRB.set_measure_callback end if IRB.conf[:MEASURE] && !IRB.conf[:MEASURE_CALLBACKS].empty? last_proc = proc do result = workspace.evaluate(code, @eval_path, line_no) end IRB.conf[:MEASURE_CALLBACKS].inject(last_proc) do |chain, item| _name, callback, arg = item proc do callback.(self, code, line_no, arg) do chain.call end end end.call else result = workspace.evaluate(code, @eval_path, line_no) end result end |
#file_input? ⇒ Boolean
Whether #io uses a File for the input_method
passed when creating the current context, see ::new
525 526 527 |
# File 'lib/irb/context.rb', line 525 def file_input? @io.class == FileInputMethod end |
#from_binding? ⇒ Boolean
599 600 601 |
# File 'lib/irb/context.rb', line 599 def from_binding? @irb.from_binding end |
#history_file ⇒ Object
A copy of the default IRB.conf[:HISTORY_FILE]
219 220 221 |
# File 'lib/irb/context.rb', line 219 def history_file IRB.conf[:HISTORY_FILE] end |
#history_file=(hist) ⇒ Object
Set IRB.conf[:HISTORY_FILE]
to the given hist
.
224 225 226 |
# File 'lib/irb/context.rb', line 224 def history_file=(hist) IRB.conf[:HISTORY_FILE] = hist end |
#home_workspace ⇒ Object
Inherited from TOPLEVEL_BINDING
.
11 12 13 14 15 16 17 |
# File 'lib/irb/ext/change-ws.rb', line 11 def home_workspace if defined? @home_workspace @home_workspace else @home_workspace = workspace end end |
#inspect ⇒ Object Also known as: to_s
:nodoc:
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/irb/context.rb', line 676 def inspect # :nodoc: array = [] for ivar in instance_variables.sort{|e1, e2| e1 <=> e2} ivar = ivar.to_s name = ivar.sub(/^@(.*)$/, '\1') val = instance_eval(ivar) case ivar when *NOPRINTING_IVARS array.push format("conf.%s=%s", name, "...") when *NO_INSPECTING_IVARS array.push format("conf.%s=%s", name, val.to_s) when *IDNAME_IVARS array.push format("conf.%s=:%s", name, val.id2name) else array.push format("conf.%s=%s", name, val.inspect) end end array.join("\n") end |
#inspect? ⇒ Boolean
Whether #inspect_mode is set or not, see #inspect_mode= for more detail.
519 520 521 |
# File 'lib/irb/context.rb', line 519 def inspect? @inspect_mode.nil? or @inspect_mode end |
#inspect_last_value ⇒ Object
:nodoc:
667 668 669 |
# File 'lib/irb/context.rb', line 667 def inspect_last_value # :nodoc: @inspect_method.inspect_value(@last_value) end |
#local_variables ⇒ Object
:nodoc:
698 699 700 |
# File 'lib/irb/context.rb', line 698 def local_variables # :nodoc: workspace.binding.local_variables end |
#main ⇒ Object
The top-level workspace, see WorkSpace#main
240 241 242 |
# File 'lib/irb/context.rb', line 240 def main workspace.main end |
#parse_command(code) ⇒ Object
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'lib/irb/context.rb', line 627 def parse_command(code) command_name, arg = code.strip.split(/\s+/, 2) return unless code.lines.size == 1 && command_name arg ||= '' command = command_name.to_sym # Command aliases are always command. example: $, @ if (alias_name = command_aliases[command]) return [alias_name, arg] end # Assignment-like expression is not a command return if arg.start_with?(ASSIGN_OPERATORS_REGEXP) && !arg.start_with?(/==|=~/) # Local variable have precedence over command return if local_variables.include?(command) # Check visibility public_method = !!Kernel.instance_method(:public_method).bind_call(main, command) rescue false private_method = !public_method && !!Kernel.instance_method(:method).bind_call(main, command) rescue false if Command.execute_as_command?(command, public_method: public_method, private_method: private_method) [command, arg] end end |
#pop_workspace ⇒ Object
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.
32 33 34 |
# File 'lib/irb/ext/workspaces.rb', line 32 def pop_workspace @workspace_stack.pop if @workspace_stack.size > 1 end |
#prompt_n ⇒ Object
TODO: Remove this when developing v2.0
319 320 321 322 |
# File 'lib/irb/context.rb', line 319 def prompt_n warn "IRB::Context#prompt_n is deprecated and will be removed in the next major release." "" end |
#prompt_n=(_) ⇒ Object
TODO: Remove this when developing v2.0
325 326 327 328 |
# File 'lib/irb/context.rb', line 325 def prompt_n=(_) warn "IRB::Context#prompt_n= is deprecated and will be removed in the next major release." "" end |
#prompting? ⇒ Boolean
Whether #verbose? is true
, and input_method
is either StdioInputMethod or RelineInputMethod or ReadlineInputMethod, see #io for more information.
486 487 488 |
# File 'lib/irb/context.rb', line 486 def prompting? verbose? || @io.prompting? end |
#push_workspace(*_main) ⇒ Object
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.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File '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) ⇒ Object
Replace the current workspace with the given workspace
.
234 235 236 237 |
# File 'lib/irb/context.rb', line 234 def replace_workspace(workspace) @workspace_stack.pop @workspace_stack.push(workspace) end |
#save_history ⇒ Object
214 215 216 |
# File 'lib/irb/context.rb', line 214 def save_history IRB.conf[:SAVE_HISTORY] end |
#save_history=(val) ⇒ Object
210 211 212 |
# File 'lib/irb/context.rb', line 210 def save_history=(val) IRB.conf[:SAVE_HISTORY] = val end |
#set_last_value(value) ⇒ Object
Sets the return value from the last statement evaluated in this context to #last_value.
495 496 497 498 |
# File 'lib/irb/context.rb', line 495 def set_last_value(value) @last_value = value workspace.local_variable_set :_, value end |
#use_loader ⇒ Object Also known as: use_loader?
Returns whether irb
‘s own file reader method is used by load
/require
or not.
This mode is globally affected (irb-wide).
37 38 39 |
# File 'lib/irb/ext/use-loader.rb', line 37 def use_loader IRB.conf[:USE_LOADER] end |
#use_loader=(opt) ⇒ Object
Sets IRB.conf[:USE_LOADER]
See #use_loader for more information.
47 48 49 50 51 |
# File 'lib/irb/ext/use-loader.rb', line 47 def use_loader=(val) self.class.remove_method(__method__) require_relative "ext/use-loader" __send__(__method__, val) end |
#use_tracer=(val) ⇒ Object
160 161 162 163 |
# File 'lib/irb/context.rb', line 160 def use_tracer=(val) require_relative "ext/tracer" if val IRB.conf[:USE_TRACER] = val end |
#verbose? ⇒ Boolean
Returns whether messages are displayed or not.
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/irb/context.rb', line 467 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 |
#workspace ⇒ Object
Workspace in the current context.
229 230 231 |
# File 'lib/irb/context.rb', line 229 def workspace @workspace_stack.last end |