Class: IRB::Formatter
- Inherits:
-
Object
- Object
- IRB::Formatter
- Defined in:
- lib/irb/formatter.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_PROMPT =
"irb(%s):%03d:%d> "
- SIMPLE_PROMPT =
">> "
- NO_PROMPT =
""
- RESULT_PREFIX =
"=>"
- SYNTAX_ERROR =
"SyntaxError: compile error\n(irb):%d: %s"
- SOURCE_ROOT =
/^#{File.('../../../', __FILE__)}/
Instance Attribute Summary collapse
-
#filter_from_backtrace ⇒ Object
readonly
Returns the value of attribute filter_from_backtrace.
-
#inspect ⇒ Object
Returns the value of attribute inspect.
- #prompt(context) ⇒ Object
Instance Method Summary collapse
- #exception(exception) ⇒ Object
- #filter_backtrace(backtrace) ⇒ Object
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
- #inspect_object(object) ⇒ Object
- #result(object) ⇒ Object
- #syntax_error(line, message) ⇒ Object
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
24 25 26 27 28 |
# File 'lib/irb/formatter.rb', line 24 def initialize @prompt = :default @inspect = true @filter_from_backtrace = [SOURCE_ROOT] end |
Instance Attribute Details
#filter_from_backtrace ⇒ Object (readonly)
Returns the value of attribute filter_from_backtrace.
22 23 24 |
# File 'lib/irb/formatter.rb', line 22 def filter_from_backtrace @filter_from_backtrace end |
#inspect ⇒ Object
Returns the value of attribute inspect.
21 22 23 |
# File 'lib/irb/formatter.rb', line 21 def inspect @inspect end |
#prompt(context) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/irb/formatter.rb', line 30 def prompt(context) case @prompt when :default then DEFAULT_PROMPT % [context.object.inspect, context.line, context.source.level] when :simple then SIMPLE_PROMPT else NO_PROMPT end end |
Instance Method Details
#exception(exception) ⇒ Object
59 60 61 62 |
# File 'lib/irb/formatter.rb', line 59 def exception(exception) backtrace = $DEBUG ? exception.backtrace : filter_backtrace(exception.backtrace) "#{exception.class.name}: #{exception.}\n\t#{backtrace.join("\n\t")}" end |
#filter_backtrace(backtrace) ⇒ Object
64 65 66 67 68 |
# File 'lib/irb/formatter.rb', line 64 def filter_backtrace(backtrace) backtrace.reject do |line| @filter_from_backtrace.any? { |pattern| pattern.match(line) } end end |
#inspect_object(object) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/irb/formatter.rb', line 39 def inspect_object(object) if @inspect result = object.respond_to?(:pretty_inspect) ? object.pretty_inspect : object.inspect result.strip! result else address = object.__id__ * 2 address += 0x100000000 if address < 0 "#<#{object.class}:0x%x>" % address end end |
#result(object) ⇒ Object
51 52 53 |
# File 'lib/irb/formatter.rb', line 51 def result(object) "#{RESULT_PREFIX} #{inspect_object(object)}" end |
#syntax_error(line, message) ⇒ Object
55 56 57 |
# File 'lib/irb/formatter.rb', line 55 def syntax_error(line, ) SYNTAX_ERROR % [line, ] end |