Class: IRB::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/irb/source.rb

Defined Under Namespace

Classes: Reflector

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bufferObject (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.

Returns:

  • (Boolean)


46
47
48
# File 'lib/irb/source.rb', line 46

def code_block?
  reflect.code_block?
end

#levelObject

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

#popObject

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

#reflectObject

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

#sourceObject 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_errorObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


56
57
58
# File 'lib/irb/source.rb', line 56

def terminate?
  reflect.terminate?
end