Class: IRB::Context

Inherits:
Object show all
Defined in:
lib/irt/extensions/irb/context.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backtrace_mapObject

Returns the value of attribute backtrace_map.



6
7
8
# File 'lib/irt/extensions/irb/context.rb', line 6

def backtrace_map
  @backtrace_map
end

#binding_fileObject

Returns the value of attribute binding_file.



6
7
8
# File 'lib/irt/extensions/irb/context.rb', line 6

def binding_file
  @binding_file
end

#binding_line_noObject

Returns the value of attribute binding_line_no.



6
7
8
# File 'lib/irt/extensions/irb/context.rb', line 6

def binding_line_no
  @binding_line_no
end

#current_lineObject

Returns the value of attribute current_line.



6
7
8
# File 'lib/irt/extensions/irb/context.rb', line 6

def current_line
  @current_line
end

#current_line_noObject (readonly)

Returns the value of attribute current_line_no.



7
8
9
# File 'lib/irt/extensions/irb/context.rb', line 7

def current_line_no
  @current_line_no
end

#irt_modeObject



27
28
29
# File 'lib/irt/extensions/irb/context.rb', line 27

def irt_mode
  @irt_mode ||= :file
end

#last_line_noObject (readonly)

Returns the value of attribute last_line_no.



7
8
9
# File 'lib/irt/extensions/irb/context.rb', line 7

def last_line_no
  @last_line_no
end

#parent_contextObject

Returns the value of attribute parent_context.



6
7
8
# File 'lib/irt/extensions/irb/context.rb', line 6

def parent_context
  @parent_context
end

#return_ignored_echo_formatObject



90
91
92
# File 'lib/irt/extensions/irb/context.rb', line 90

def return_ignored_echo_format
  IRT.dye @return_ignored_echo_format, :ignored_color
end

Instance Method Details

#evaluate(line, line_no) ⇒ Object



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
# File 'lib/irt/extensions/irb/context.rb', line 32

def evaluate(line, line_no)
  @current_line = line
  @current_line_no = line_no + line.chomp.count("\n")
  if @exception_raised
    IRT::Session.enter(:interactive) if irt_mode == :file
    @exception_raised = false
  end
  log_file_line(line_no) if irt_mode == :file
  begin
    # skip setting last_value for non_setting_commands
    if line =~ /^\s*(#{quoted_option_string(IRT.log.non_setting_commands)})\b(.*)$/
      command, args = $1, $2
      if command =~ /^(sh|ri|pri)$/ && irt_mode != :file
        args = args.strip if args
        line = if args.match(/^('|").+\1$/)
                 command == 'sh' ? "#{command} #{args}" : "#{command} #{args}, true"
               else
                 args = "%(#{args})" unless args.empty?
                 "#{command} #{args}"
               end
      end
      IRT::Commands::Ri.reset_choices_map unless command =~ /^(ri|pri)$/
      self.echo = false
      res = @workspace.evaluate(self, line, irb_path, line_no)
      if command =~ /^(#{IRT.log.ignored_echo_commands * '|'})$/
        output_ignored_echo_value(res)
      end
    else
      self.echo = irt_mode == :file ? false : true
      evaluate_and_set_last_value(line, line_no)
    end
  rescue Exception => e
    @exception_raised = true
    process_exception(e)
    print Dye.sgr(IRT.dye_styles[:error_color]) if Dye.color?
    raise
  else
    log_session_line(line, line_no) unless irt_mode == :file
  end
end

#evaluate_and_set_last_valueObject



31
# File 'lib/irt/extensions/irb/context.rb', line 31

alias_method :evaluate_and_set_last_value, :evaluate

#file_line_pointersObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/irt/extensions/irb/context.rb', line 10

def file_line_pointers
  file = line = nil
  c = self
  until file
    case c.irt_mode
    when :binding
      file = c.binding_file
      line = c.binding_line_no
    when :file
      file = c.irb_path
      line = c.last_line_no
    end
    c = c.parent_context
  end
  [file, line]
end

#original_prompt_modeObject



94
# File 'lib/irt/extensions/irb/context.rb', line 94

alias_method :original_prompt_mode, :prompt_mode=

#prompt_mode=(mode) ⇒ Object



95
96
97
98
# File 'lib/irt/extensions/irb/context.rb', line 95

def prompt_mode=(mode)
  original_prompt_mode(mode)
  @return_ignored_echo_format = IRB.conf[:PROMPT][mode][:RETURN_I] || "   #> %s\n"
end

#return_formatObject



86
87
88
# File 'lib/irt/extensions/irb/context.rb', line 86

def return_format
  IRT.dye @return_format, :actual_color
end