Class IRB::Context
In: lib/irb/context.rb
lib/irb/ext/workspaces.rb
lib/irb/ext/tracer.rb
lib/irb/ext/history.rb
lib/irb/ext/use-loader.rb
lib/irb/ext/change-ws.rb
lib/irb/ext/math-mode.rb
lib/irb/ext/save-history.rb
Parent: Object

Methods

Constants

NOPRINTING_IVARS = ["@last_value"]
NO_INSPECTING_IVARS = ["@irb", "@io"]
IDNAME_IVARS = ["@prompt_mode"]

External Aliases

use_readline -> use_readline?
rc -> rc?
ignore_sigint -> ignore_sigint?
ignore_eof -> ignore_eof?
echo -> echo?
exit -> __exit__
inspect -> __inspect__
to_s -> __to_s__
use_tracer -> use_tracer?
math_mode -> math?

Attributes

ap_name  [RW] 
auto_indent_mode  [RW] 
back_trace_limit  [RW] 
debug_level  [R] 
echo  [RW] 
eval_history  [R] 
ignore_eof  [RW] 
ignore_sigint  [RW] 
inspect_mode  [R] 
io  [RW] 
irb  [RW] 
irb_name  [R] 
irb_name  [RW] 
irb_path  [RW] 
last_value  [R] 
load_modules  [RW] 
math_mode  [R] 
prompt_c  [RW] 
prompt_i  [RW] 
prompt_mode  [R] 
prompt_n  [RW] 
prompt_s  [RW] 
rc  [RW] 
return_format  [RW] 
thread  [R] 
use_readline  [R] 
use_tracer  [R] 
verbose  [RW] 
workspace  [RW] 
workspace_home  [R] 

Public Class methods

Arguments:

  input_method: nil -- stdin or readline
                String -- File
                other -- using this as InputMethod

[Source]

     # File lib/irb/context.rb, line 22
 22:     def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
 23:       @irb = irb
 24:       if workspace
 25:         @workspace = workspace
 26:       else
 27:         @workspace = WorkSpace.new
 28:       end
 29:       @thread = Thread.current if defined? Thread
 30: #      @irb_level = 0
 31: 
 32:       # copy of default configuration
 33:       @ap_name = IRB.conf[:AP_NAME]
 34:       @rc = IRB.conf[:RC]
 35:       @load_modules = IRB.conf[:LOAD_MODULES]
 36: 
 37:       @use_readline = IRB.conf[:USE_READLINE]
 38:       @inspect_mode = IRB.conf[:INSPECT_MODE]
 39: 
 40:       self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
 41:       self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
 42:       self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
 43:       self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
 44: 
 45:       @ignore_sigint = IRB.conf[:IGNORE_SIGINT]
 46:       @ignore_eof = IRB.conf[:IGNORE_EOF]
 47: 
 48:       @back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
 49:       
 50:       self.prompt_mode = IRB.conf[:PROMPT_MODE]
 51: 
 52:       if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
 53:         @irb_name = IRB.conf[:IRB_NAME]
 54:       else
 55:         @irb_name = "irb#"+IRB.JobManager.n_jobs.to_s
 56:       end
 57:       @irb_path = "(" + @irb_name + ")"
 58: 
 59:       case input_method
 60:       when nil
 61:         case use_readline?
 62:         when nil
 63:           if (defined?(ReadlineInputMethod) && STDIN.tty? &&
 64:               IRB.conf[:PROMPT_MODE] != :INF_RUBY)
 65:             @io = ReadlineInputMethod.new
 66:           else
 67:             @io = StdioInputMethod.new
 68:           end
 69:         when false
 70:           @io = StdioInputMethod.new
 71:         when true
 72:           if defined?(ReadlineInputMethod)
 73:             @io = ReadlineInputMethod.new
 74:           else
 75:             @io = StdioInputMethod.new
 76:           end
 77:         end
 78: 
 79:       when String
 80:         @io = FileInputMethod.new(input_method)
 81:         @irb_name = File.basename(input_method)
 82:         @irb_path = input_method
 83:       else
 84:         @io = input_method
 85:       end
 86:       self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
 87: 
 88:       if output_method
 89:         @output_method = output_method
 90:       else
 91:         @output_method = StdioOutputMethod.new
 92:       end
 93: 
 94:       @verbose = IRB.conf[:VERBOSE] 
 95:       @echo = IRB.conf[:ECHO]
 96:       if @echo.nil?
 97:         @echo = true
 98:       end
 99:       @debug_level = IRB.conf[:DEBUG_LEVEL]
100:     end

Public Instance methods

_set_last_value(value)

Alias for set_last_value

[Source]

    # File lib/irb/ext/change-ws.rb, line 24
24:     def change_workspace(*_main)
25:       if _main.empty?
26:         @workspace = home_workspace 
27:         return main
28:       end
29:       
30:       @workspace = WorkSpace.new(_main[0])
31:       
32:       if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
33:         main.extend ExtendCommandBundle
34:       end
35:     end

[Source]

     # File lib/irb/context.rb, line 213
213:     def debug?
214:       @debug_level > 0
215:     end

[Source]

     # File lib/irb/context.rb, line 207
207:     def debug_level=(value)
208:       @debug_level = value
209:       RubyLex.debug_level = value
210:       SLex.debug_level = value
211:     end

[Source]

    # File lib/irb/ext/history.rb, line 34
34:     def eval_history=(no)
35:       if no
36:         if defined?(@eval_history) && @eval_history
37:           @eval_history_values.size(no)
38:         else
39:           @eval_history_values = History.new(no)
40:           IRB.conf[:__TMP__EHV__] = @eval_history_values
41:           @workspace.evaluate(self, "__ = IRB.conf[:__TMP__EHV__]")
42:           IRB.conf.delete(:__TMP_EHV__)
43:         end
44:       else
45:         @eval_history_values = nil
46:       end
47:       @eval_history = no
48:     end

[Source]

     # File lib/irb/context.rb, line 217
217:     def evaluate(line, line_no)
218:       @line_no = line_no
219:       set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
220: #      @workspace.evaluate("_ = IRB.conf[:MAIN_CONTEXT]._")
221: #      @_ = @workspace.evaluate(line, irb_path, line_no)
222:     end

[Source]

     # File lib/irb/context.rb, line 225
225:     def exit(ret = 0)
226:       IRB.irb_exit(@irb, ret)
227:     end

[Source]

     # File lib/irb/context.rb, line 188
188:     def file_input?
189:       @io.class == FileInputMethod
190:     end

[Source]

    # File lib/irb/ext/save-history.rb, line 41
41:     def history_file
42:       IRB.conf[:HISTORY_FILE]
43:     end

[Source]

    # File lib/irb/ext/save-history.rb, line 45
45:     def history_file=(hist)
46:       IRB.conf[:HISTORY_FILE] = hist
47:     end

[Source]

    # File lib/irb/ext/change-ws.rb, line 16
16:     def home_workspace
17:       if defined? @home_workspace
18:         @home_workspace
19:       else
20:         @home_workspace = @workspace
21:       end
22:     end

[Source]

    # File lib/irb/ext/save-history.rb, line 22
22:     def init_save_history
23:       unless (class<<@io;self;end).include?(HistorySavingAbility)
24:         @io.extend(HistorySavingAbility)
25:       end
26:     end

[Source]

     # File lib/irb/context.rb, line 234
234:     def inspect
235:       array = []
236:       for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
237:         name = ivar.sub(/^@(.*)$/){$1}
238:         val = instance_eval(ivar)
239:         case ivar
240:         when *NOPRINTING_IVARS
241:           array.push format("conf.%s=%s", name, "...")
242:         when *NO_INSPECTING_IVARS
243:           array.push format("conf.%s=%s", name, val.to_s)
244:         when *IDNAME_IVARS
245:           array.push format("conf.%s=:%s", name, val.id2name)
246:         else
247:           array.push format("conf.%s=%s", name, val.inspect)
248:         end
249:       end
250:       array.join("\n")
251:     end

[Source]

    # File lib/irb/ext/math-mode.rb, line 32
32:     def inspect?
33:       @inspect_mode.nil? && !@math_mode or @inspect_mode
34:     end

[Source]

     # File lib/irb/context.rb, line 184
184:     def inspect?
185:       @inspect_mode.nil? or @inspect_mode
186:     end

[Source]

     # File lib/irb/context.rb, line 192
192:     def inspect_mode=(opt)
193:       if opt
194:         @inspect_mode = opt
195:       else
196:         @inspect_mode = !@inspect_mode
197:       end
198:       print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
199:       @inspect_mode
200:     end

[Source]

    # File lib/irb/ext/workspaces.rb, line 16
16:     def irb_level
17:       workspace_stack.size
18:     end

[Source]

     # File lib/irb/context.rb, line 102
102:     def main
103:       @workspace.main
104:     end

[Source]

    # File lib/irb/ext/math-mode.rb, line 19
19:     def math_mode=(opt)
20:       if @math_mode == true && opt == false
21:         IRB.fail CantReturnToNormalMode
22:         return
23:       end
24: 
25:       @math_mode = opt
26:       if math_mode
27:         main.extend Math
28:         print "start math mode\n" if verbose?
29:       end
30:     end

[Source]

    # File lib/irb/ext/workspaces.rb, line 47
47:     def pop_workspace
48:       if workspaces.empty?
49:         print "workspace stack empty\n"
50:         return
51:       end
52:       @workspace = workspaces.pop
53:     end

[Source]

     # File lib/irb/context.rb, line 169
169:     def prompt_mode=(mode)
170:       @prompt_mode = mode
171:       pconf = IRB.conf[:PROMPT][mode]
172:       @prompt_i = pconf[:PROMPT_I]
173:       @prompt_s = pconf[:PROMPT_S]
174:       @prompt_c = pconf[:PROMPT_C]
175:       @prompt_n = pconf[:PROMPT_N]
176:       @return_format = pconf[:RETURN]
177:       if ai = pconf.include?(:AUTO_INDENT)
178:         @auto_indent_mode = ai
179:       else
180:         @auto_indent_mode = IRB.conf[:AUTO_INDENT]
181:       end
182:     end

[Source]

     # File lib/irb/context.rb, line 155
155:     def prompting?
156:       verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
157:                 (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
158:     end

[Source]

    # File lib/irb/ext/workspaces.rb, line 28
28:     def push_workspace(*_main)
29:       if _main.empty?
30:         if workspaces.empty?
31:           print "No other workspace\n"
32:           return nil
33:         end
34:         ws = workspaces.pop
35:         workspaces.push @workspace
36:         @workspace = ws
37:         return workspaces
38:       end
39: 
40:       workspaces.push @workspace
41:       @workspace = WorkSpace.new(@workspace.binding, _main[0])
42:       if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
43:         main.extend ExtendCommandBundle
44:       end
45:     end

[Source]

    # File lib/irb/ext/save-history.rb, line 28
28:     def save_history
29:       IRB.conf[:SAVE_HISTORY]
30:     end

[Source]

    # File lib/irb/ext/save-history.rb, line 32
32:     def save_history=(val)
33:       IRB.conf[:SAVE_HISTORY] = val
34:       if val
35:         main_context = IRB.conf[:MAIN_CONTEXT]
36:         main_context = self unless main_context
37:         main_context.init_save_history
38:       end
39:     end

[Source]

     # File lib/irb/context.rb, line 162
162:     def set_last_value(value)
163:       @last_value = value
164:       @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
165:     end

[Source]

    # File lib/irb/ext/history.rb, line 21
21:     def set_last_value(value)
22:       _set_last_value(value)
23: 
24: #      @workspace.evaluate self, "_ = IRB.CurrentContext.last_value"
25:       if @eval_history #and !@eval_history_values.equal?(llv)
26:         @eval_history_values.push @line_no, @last_value
27:         @workspace.evaluate self, "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
28:       end
29: 
30:       @last_value
31:     end
to_s()

Alias for inspect

[Source]

    # File lib/irb/ext/use-loader.rb, line 35
35:     def use_loader
36:       IRB.conf[:USE_LOADER]
37:     end

[Source]

    # File lib/irb/ext/use-loader.rb, line 41
41:     def use_loader=(opt)
42: 
43:       if IRB.conf[:USE_LOADER] != opt
44:         IRB.conf[:USE_LOADER] = opt
45:         if opt
46:           if !$".include?("irb/cmd/load")
47:           end
48:           (class<<@workspace.main;self;end).instance_eval {
49:             alias_method :load, :irb_load
50:             alias_method :require, :irb_require
51:           }
52:         else
53:           (class<<@workspace.main;self;end).instance_eval {
54:             alias_method :load, :__original__load__IRB_use_loader__
55:             alias_method :require, :__original__require__IRB_use_loader__
56:           }
57:         end
58:       end
59:       print "Switch to load/require#{unless use_loader; ' non';end} trace mode.\n" if verbose?
60:       opt
61:     end
use_loader?()

Alias for use_loader

[Source]

     # File lib/irb/context.rb, line 202
202:     def use_readline=(opt)
203:       @use_readline = opt
204:       print "use readline module\n" if @use_readline
205:     end

[Source]

    # File lib/irb/ext/tracer.rb, line 30
30:     def use_tracer=(opt)
31:       if opt
32:         Tracer.set_get_line_procs(@irb_path) {
33:           |line_no, *rests|
34:           @io.line(line_no)
35:         }
36:       elsif !opt && @use_tracer
37:         Tracer.off
38:       end
39:       @use_tracer=opt
40:     end

[Source]

     # File lib/irb/context.rb, line 143
143:     def verbose?
144:       if @verbose.nil?
145:         if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod) 
146:           false
147:         elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
148:           true
149:         else
150:           false
151:         end
152:       end
153:     end

[Source]

    # File lib/irb/ext/workspaces.rb, line 20
20:     def workspaces
21:       if defined? @workspaces
22:         @workspaces
23:       else
24:         @workspaces = []
25:       end
26:     end

[Validate]