Class: IRB::Context
- Defined in:
- 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
Instance Attribute Summary collapse
-
#eval_history ⇒ Object
The command result history limit.
-
#use_tracer ⇒ Object
(also: #use_tracer?)
Whether Tracer is used when evaluating statements in this context.
Instance Method Summary collapse
-
#_set_last_value ⇒ Object
See #set_last_value.
-
#change_workspace(*_main) ⇒ Object
Changes the current workspace to given object or binding.
-
#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:.
-
#irb_level ⇒ Object
Size of the current WorkSpace stack.
-
#pop_workspace ⇒ Object
Removes the last element from the current #workspaces stack and returns it, or
nil
if the current workspace stack is empty. -
#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 givenval
and calls #init_save_history with this context. - #set_last_value(value) ⇒ Object
-
#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.
-
#workspaces ⇒ Object
WorkSpaces in the current stack.
Instance Attribute Details
#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 |
#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 |
Instance Method Details
#_set_last_value ⇒ Object
See #set_last_value
20 |
# File 'lib/irb/ext/history.rb', line 20 alias _set_last_value set_last_value |
#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 |
#history_file ⇒ Object
A copy of the default IRB.conf[:HISTORY_FILE]
50 51 52 |
# File 'lib/irb/ext/save-history.rb', line 50 def history_file IRB.conf[:HISTORY_FILE] end |
#history_file=(hist) ⇒ Object
Set IRB.conf[:HISTORY_FILE]
to the given hist
.
55 56 57 |
# File 'lib/irb/ext/save-history.rb', line 55 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:
19 20 21 22 23 |
# File 'lib/irb/ext/save-history.rb', line 19 def init_save_history# :nodoc: unless (class<<@io;self;end).include?(HistorySavingAbility) @io.extend(HistorySavingAbility) end 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 |
#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 |
#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]
26 27 28 |
# File 'lib/irb/ext/save-history.rb', line 26 def save_history IRB.conf[:SAVE_HISTORY] end |
#save_history=(val) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/irb/ext/save-history.rb', line 40 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
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/irb/ext/history.rb', line 22 def set_last_value(value) _set_last_value(value) if defined?(@eval_history) && @eval_history @eval_history_values.push @line_no, @last_value @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}" end @last_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).
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
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 |
#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 |