Class: IRB::Context
- Defined in:
- lib/irb/context.rb,
lib/irb/ext/tracer.rb,
lib/irb/ext/history.rb,
lib/irb/ext/change-ws.rb,
lib/irb/ext/use-loader.rb,
lib/irb/ext/workspaces.rb,
lib/irb/ext/save-history.rb
Overview
:nodoc:
Constant Summary collapse
- 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
nand 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 either the #irb_name surrounded by parenthesis, or the
input_methodpassed to Context.new. -
#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_n ⇒ Object
See IRB@Customizing+the+IRB+Prompt for more information.
-
#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
:RETURNof themodepassed 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.
-
#use_tracer ⇒ Object
(also: #use_tracer?)
Whether Tracer is used when evaluating statements in this context.
-
#verbose ⇒ Object
Whether verbose messages are displayed or not.
-
#workspace ⇒ Object
WorkSpace in the current context.
-
#workspace_home ⇒ Object
readonly
The toplevel workspace, see #home_workspace.
Instance Method Summary collapse
- #__exit__ ⇒ Object
- #__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.
-
#evaluate(line, line_no, exception: nil) ⇒ Object
:nodoc:.
-
#exit(ret = 0) ⇒ Object
Exits the current session, see IRB.irb_exit.
-
#file_input? ⇒ Boolean
Whether #io uses a File for the
input_methodpassed when creating the current context, see ::new. -
#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. -
#init_save_history ⇒ Object
:nodoc:.
-
#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:.
-
#irb_level ⇒ Object
Size of the current WorkSpace stack.
-
#local_variables ⇒ Object
:nodoc:.
-
#main ⇒ Object
The top-level workspace, see WorkSpace#main.
-
#pop_workspace ⇒ Object
Removes the last element from the current #workspaces stack and returns it, or
nilif the current workspace stack is empty. -
#prompting? ⇒ Boolean
Whether #verbose? is
true, andinput_methodis 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.
-
#save_history ⇒ Object
A copy of the default
IRB.conf[:SAVE_HISTORY]. -
#save_history=(val) ⇒ Object
Sets
IRB.conf[:SAVE_HISTORY]to the givenvaland calls #init_save_history with this context. -
#set_last_value(value) ⇒ Object
Sets the return value from the last statement evaluated in this context to #last_value.
-
#symbol_alias?(command) ⇒ Boolean
Return true if it’s aliased from the argument and it’s not an identifier.
-
#transform_args?(command) ⇒ Boolean
Return true if the command supports transforming args.
-
#use_loader ⇒ Object
(also: #use_loader?)
Returns whether
irb‘s own file reader method is used byload/requireor not. -
#use_loader=(opt) ⇒ Object
Sets
IRB.conf[:USE_LOADER]. -
#verbose? ⇒ Boolean
Returns whether messages are displayed or not.
-
#workspaces ⇒ Object
WorkSpaces in the current stack.
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
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 154 155 156 157 |
# File 'lib/irb/context.rb', line 28 def initialize(irb, workspace = nil, input_method = nil) @irb = irb if workspace @workspace = workspace else @workspace = 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] if 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 @irb_path = "(" + @irb_name + ")" case input_method when nil @io = nil case use_multiline? when nil if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline? # Both of multiline mode and singleline mode aren't specified. @io = RelineInputMethod.new else @io = nil end when false @io = nil when true @io = RelineInputMethod.new end unless @io case use_singleline? when nil if (defined?(ReadlineInputMethod) && STDIN.tty? && 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 = '-' @irb_path = '-' when String @io = FileInputMethod.new(input_method) @irb_name = File.basename(input_method) @irb_path = input_method else @io = input_method end self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY] @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] end |
Instance Attribute Details
#ap_name ⇒ Object
A copy of the default IRB.conf[:AP_NAME]
180 181 182 |
# File 'lib/irb/context.rb', line 180 def ap_name @ap_name end |
#auto_indent_mode ⇒ Object
239 240 241 |
# File 'lib/irb/context.rb', line 239 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.
See IRB@Command+line+options for more command line options.
332 333 334 |
# File 'lib/irb/context.rb', line 332 def back_trace_limit @back_trace_limit end |
#command_aliases ⇒ Object
User-defined IRB command aliases
335 336 337 |
# File 'lib/irb/context.rb', line 335 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
270 271 272 |
# File 'lib/irb/context.rb', line 270 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
305 306 307 |
# File 'lib/irb/context.rb', line 305 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).
37 38 39 |
# File 'lib/irb/ext/history.rb', line 37 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.
259 260 261 |
# File 'lib/irb/context.rb', line 259 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.
256 257 258 |
# File 'lib/irb/context.rb', line 256 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.
252 253 254 |
# File 'lib/irb/context.rb', line 252 def ignore_sigint @ignore_sigint end |
#inspect_mode ⇒ Object
A copy of the default IRB.conf[:INSPECT_MODE]
205 206 207 |
# File 'lib/irb/context.rb', line 205 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.
175 176 177 |
# File 'lib/irb/context.rb', line 175 def io @io end |
#irb ⇒ Object
Current irb session.
178 179 180 |
# File 'lib/irb/context.rb', line 178 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
187 188 189 |
# File 'lib/irb/context.rb', line 187 def irb_name @irb_name end |
#irb_path ⇒ Object
Can be either the #irb_name surrounded by parenthesis, or the input_method passed to Context.new
190 191 192 |
# File 'lib/irb/context.rb', line 190 def irb_path @irb_path end |
#last_value ⇒ Object (readonly)
The return value of the last statement evaluated.
386 387 388 |
# File 'lib/irb/context.rb', line 386 def last_value @last_value end |
#load_modules ⇒ Object
A copy of the default IRB.conf[:LOAD_MODULES]
184 185 186 |
# File 'lib/irb/context.rb', line 184 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
319 320 321 |
# File 'lib/irb/context.rb', line 319 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 IRB@Customizing+the+IRB+Prompt for more information.
220 221 222 |
# File 'lib/irb/context.rb', line 220 def prompt_c @prompt_c end |
#prompt_i ⇒ Object
Standard IRB prompt.
See IRB@Customizing+the+IRB+Prompt for more information.
212 213 214 |
# File 'lib/irb/context.rb', line 212 def prompt_i @prompt_i end |
#prompt_mode ⇒ Object
A copy of the default IRB.conf[:PROMPT_MODE]
208 209 210 |
# File 'lib/irb/context.rb', line 208 def prompt_mode @prompt_mode end |
#prompt_n ⇒ Object
See IRB@Customizing+the+IRB+Prompt for more information.
222 223 224 |
# File 'lib/irb/context.rb', line 222 def prompt_n @prompt_n end |
#prompt_s ⇒ Object
IRB prompt for continuated strings.
See IRB@Customizing+the+IRB+Prompt for more information.
216 217 218 |
# File 'lib/irb/context.rb', line 216 def prompt_s @prompt_s end |
#rc ⇒ Object Also known as: rc?
A copy of the default IRB.conf[:RC]
182 183 184 |
# File 'lib/irb/context.rb', line 182 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.
242 243 244 |
# File 'lib/irb/context.rb', line 242 def return_format @return_format end |
#thread ⇒ Object (readonly)
The current thread in this context.
169 170 171 |
# File 'lib/irb/context.rb', line 169 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]
203 204 205 |
# File 'lib/irb/context.rb', line 203 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]
195 196 197 |
# File 'lib/irb/context.rb', line 195 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]
199 200 201 |
# File 'lib/irb/context.rb', line 199 def use_singleline @use_singleline end |
#use_tracer ⇒ Object Also known as: use_tracer?
Whether Tracer is used when evaluating statements in this context.
See lib/tracer.rb for more information.
43 44 45 |
# File 'lib/irb/ext/tracer.rb', line 43 def use_tracer @use_tracer end |
#verbose ⇒ Object
Whether verbose messages are displayed or not.
A copy of the default IRB.conf[:VERBOSE]
323 324 325 |
# File 'lib/irb/context.rb', line 323 def verbose @verbose end |
#workspace ⇒ Object
WorkSpace in the current context.
167 168 169 |
# File 'lib/irb/context.rb', line 167 def workspace @workspace end |
#workspace_home ⇒ Object (readonly)
The toplevel workspace, see #home_workspace
165 166 167 |
# File 'lib/irb/context.rb', line 165 def workspace_home @workspace_home end |
Instance Method Details
#__exit__ ⇒ Object
509 |
# File 'lib/irb/context.rb', line 509 alias __exit__ exit |
#__inspect__ ⇒ Object
521 |
# File 'lib/irb/context.rb', line 521 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
20 21 22 23 |
# File 'lib/irb/ext/history.rb', line 20 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.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/irb/ext/change-ws.rb', line 32 def change_workspace(*_main) if _main.empty? @workspace = home_workspace return main end @workspace = WorkSpace.new(_main[0]) if !(class<<main;ancestors;end).include?(ExtendCommandBundle) main.extend ExtendCommandBundle end end |
#evaluate(line, line_no, exception: nil) ⇒ Object
:nodoc:
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/irb/context.rb', line 481 def evaluate(line, line_no, exception: nil) # :nodoc: @line_no = line_no if exception line_no -= 1 line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end" @workspace.local_variable_set(:_, exception) end # Transform a non-identifier alias (@, $) or keywords (next, break) command, args = line.split(/\s/, 2) if original = command_aliases[command.to_sym] line = line.gsub(/\A#{Regexp.escape(command)}/, original.to_s) command = original end # Hook command-specific transformation command_class = ExtendCommandBundle.load_command(command) if command_class&.respond_to?(:transform_args) line = "#{command} #{command_class.transform_args(args)}" end set_last_value(@workspace.evaluate(self, line, irb_path, line_no)) end |
#exit(ret = 0) ⇒ Object
Exits the current session, see IRB.irb_exit
511 512 513 514 515 |
# File 'lib/irb/context.rb', line 511 def exit(ret = 0) IRB.irb_exit(@irb, ret) rescue UncaughtThrowError super end |
#file_input? ⇒ Boolean
Whether #io uses a File for the input_method passed when creating the current context, see ::new
421 422 423 |
# File 'lib/irb/context.rb', line 421 def file_input? @io.class == FileInputMethod end |
#history_file ⇒ Object
A copy of the default IRB.conf[:HISTORY_FILE]
48 49 50 |
# File 'lib/irb/ext/save-history.rb', line 48 def history_file IRB.conf[:HISTORY_FILE] end |
#history_file=(hist) ⇒ Object
Set IRB.conf[:HISTORY_FILE] to the given hist.
53 54 55 |
# File 'lib/irb/ext/save-history.rb', line 53 def history_file=(hist) IRB.conf[:HISTORY_FILE] = hist end |
#home_workspace ⇒ Object
Inherited from TOPLEVEL_BINDING.
17 18 19 20 21 22 23 |
# File 'lib/irb/ext/change-ws.rb', line 17 def home_workspace if defined? @home_workspace @home_workspace else @home_workspace = @workspace end end |
#init_save_history ⇒ Object
:nodoc:
17 18 19 20 21 |
# File 'lib/irb/ext/save-history.rb', line 17 def init_save_history# :nodoc: unless (class<<@io;self;end).include?(HistorySavingAbility) @io.extend(HistorySavingAbility) end end |
#inspect ⇒ Object Also known as: to_s
:nodoc:
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/irb/context.rb', line 522 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.
415 416 417 |
# File 'lib/irb/context.rb', line 415 def inspect? @inspect_mode.nil? or @inspect_mode end |
#inspect_last_value ⇒ Object
:nodoc:
505 506 507 |
# File 'lib/irb/context.rb', line 505 def inspect_last_value # :nodoc: @inspect_method.inspect_value(@last_value) end |
#irb_level ⇒ Object
Size of the current WorkSpace stack
17 18 19 |
# File 'lib/irb/ext/workspaces.rb', line 17 def irb_level workspace_stack.size end |
#local_variables ⇒ Object
:nodoc:
544 545 546 |
# File 'lib/irb/context.rb', line 544 def local_variables # :nodoc: workspace.binding.local_variables end |
#main ⇒ Object
The top-level workspace, see WorkSpace#main
160 161 162 |
# File 'lib/irb/context.rb', line 160 def main @workspace.main 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.
58 59 60 61 62 63 64 |
# File 'lib/irb/ext/workspaces.rb', line 58 def pop_workspace if workspaces.empty? print "workspace stack empty\n" return end @workspace = workspaces.pop end |
#prompting? ⇒ Boolean
Whether #verbose? is true, and input_method is either StdioInputMethod or RelineInputMethod or ReadlineInputMethod, see #io for more information.
379 380 381 382 383 |
# File 'lib/irb/context.rb', line 379 def prompting? verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) || @io.kind_of?(RelineInputMethod) || (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod))) 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/irb/ext/workspaces.rb', line 35 def push_workspace(*_main) if _main.empty? if workspaces.empty? print "No other workspace\n" return nil end ws = workspaces.pop workspaces.push @workspace @workspace = ws return workspaces end workspaces.push @workspace @workspace = WorkSpace.new(@workspace.binding, _main[0]) if !(class<<main;ancestors;end).include?(ExtendCommandBundle) main.extend ExtendCommandBundle end end |
#save_history ⇒ Object
A copy of the default IRB.conf[:SAVE_HISTORY]
24 25 26 |
# File 'lib/irb/ext/save-history.rb', line 24 def save_history IRB.conf[:SAVE_HISTORY] end |
#save_history=(val) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/irb/ext/save-history.rb', line 38 def save_history=(val) IRB.conf[:SAVE_HISTORY] = val if val main_context = IRB.conf[:MAIN_CONTEXT] main_context = self unless main_context main_context.init_save_history end end |
#set_last_value(value) ⇒ Object
Sets the return value from the last statement evaluated in this context to #last_value.
390 391 392 393 |
# File 'lib/irb/context.rb', line 390 def set_last_value(value) @last_value = value @workspace.local_variable_set :_, value end |
#symbol_alias?(command) ⇒ Boolean
Return true if it’s aliased from the argument and it’s not an identifier.
549 550 551 552 |
# File 'lib/irb/context.rb', line 549 def symbol_alias?(command) return nil if command.match?(/\A\w+\z/) command_aliases.key?(command.to_sym) end |
#transform_args?(command) ⇒ Boolean
Return true if the command supports transforming args
555 556 557 558 |
# File 'lib/irb/context.rb', line 555 def transform_args?(command) command = command_aliases.fetch(command.to_sym, command) ExtendCommandBundle.load_command(command)&.respond_to?(:transform_args) 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).
43 44 45 |
# File 'lib/irb/ext/use-loader.rb', line 43 def use_loader IRB.conf[:USE_LOADER] end |
#use_loader=(opt) ⇒ Object
Sets IRB.conf[:USE_LOADER]
See #use_loader for more information.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/irb/ext/use-loader.rb', line 53 def use_loader=(opt) if IRB.conf[:USE_LOADER] != opt IRB.conf[:USE_LOADER] = opt if opt if !$".include?("irb/cmd/load") end (class<<@workspace.main;self;end).instance_eval { alias_method :load, :irb_load alias_method :require, :irb_require } else (class<<@workspace.main;self;end).instance_eval { alias_method :load, :__original__load__IRB_use_loader__ alias_method :require, :__original__require__IRB_use_loader__ } end end print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose? opt end |
#verbose? ⇒ Boolean
Returns whether messages are displayed or not.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/irb/context.rb', line 360 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 |
#workspaces ⇒ Object
WorkSpaces in the current stack
22 23 24 25 26 27 28 |
# File 'lib/irb/ext/workspaces.rb', line 22 def workspaces if defined? @workspaces @workspaces else @workspaces = [] end end |