Class: IRB::Source
- Inherits:
-
Object
- Object
- IRB::Source
- Defined in:
- lib/irb/source.rb
Defined Under Namespace
Classes: Reflector
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
-
#<<(source) ⇒ Object
Adds a source line to the buffer and flushes the cached reflection.
-
#code_block? ⇒ Boolean
Reflects on the accumulated source to see if it’s a valid code block.
-
#initialize(buffer = []) ⇒ Source
constructor
A new instance of Source.
-
#level ⇒ Object
Reflects on the accumulated source and returns the current code block indentation level.
-
#pop ⇒ Object
Removes the last line from the buffer and flushes the cached reflection.
-
#reflect ⇒ Object
Returns a Reflector for the accumulated source and caches it.
-
#source ⇒ Object
(also: #to_s)
Returns the accumulated source as a string, joined by newlines.
-
#syntax_error ⇒ Object
Reflects on the accumulated source and returns the actual syntax error message if one occurs.
-
#syntax_error? ⇒ Boolean
Reflects on the accumulated source to see if it contains a syntax error.
-
#terminate? ⇒ Boolean
Reflects on the accumulated source to see if it contains a terminate signal.
Constructor Details
#initialize(buffer = []) ⇒ Source
Returns a new instance of Source.
13 14 15 |
# File 'lib/irb/source.rb', line 13 def initialize(buffer = []) @buffer = buffer end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
11 12 13 |
# File 'lib/irb/source.rb', line 11 def buffer @buffer end |
Instance Method Details
#<<(source) ⇒ Object
Adds a source line to the buffer and flushes the cached reflection.
18 19 20 21 22 23 24 |
# File 'lib/irb/source.rb', line 18 def <<(source) source = source.rstrip unless source.empty? @reflection = nil @buffer << source end end |
#code_block? ⇒ Boolean
Reflects on the accumulated source to see if it’s a valid code block.
46 47 48 |
# File 'lib/irb/source.rb', line 46 def code_block? reflect.code_block? end |
#level ⇒ Object
Reflects on the accumulated source and returns the current code block indentation level.
41 42 43 |
# File 'lib/irb/source.rb', line 41 def level reflect.level end |
#pop ⇒ Object
Removes the last line from the buffer and flushes the cached reflection.
27 28 29 30 |
# File 'lib/irb/source.rb', line 27 def pop @reflection = nil @buffer.pop end |
#reflect ⇒ Object
Returns a Reflector for the accumulated source and caches it.
67 68 69 |
# File 'lib/irb/source.rb', line 67 def reflect @reflection ||= Reflector.new(source) end |
#source ⇒ Object Also known as: to_s
Returns the accumulated source as a string, joined by newlines.
33 34 35 |
# File 'lib/irb/source.rb', line 33 def source @buffer.join("\n") end |
#syntax_error ⇒ Object
Reflects on the accumulated source and returns the actual syntax error message if one occurs.
62 63 64 |
# File 'lib/irb/source.rb', line 62 def syntax_error reflect.syntax_error end |
#syntax_error? ⇒ Boolean
Reflects on the accumulated source to see if it contains a syntax error.
51 52 53 |
# File 'lib/irb/source.rb', line 51 def syntax_error? reflect.syntax_error? end |
#terminate? ⇒ Boolean
Reflects on the accumulated source to see if it contains a terminate signal.
56 57 58 |
# File 'lib/irb/source.rb', line 56 def terminate? reflect.terminate? end |