Class: SeeingIsBelieving::Debugger

Inherits:
Object
  • Object
show all
Defined in:
lib/seeing_is_believing/debugger.rb

Constant Summary collapse

CONTEXT_COLOUR =

background blue

"\e[37;44m"
RESET_COLOUR =
"\e[0m"
Null =
new stream: nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Debugger

Returns a new instance of Debugger.



6
7
8
9
# File 'lib/seeing_is_believing/debugger.rb', line 6

def initialize(options={})
  @coloured = options[:colour]
  @stream   = options[:stream]
end

Instance Attribute Details

#streamObject (readonly) Also known as: enabled?

Returns the value of attribute stream.



17
18
19
# File 'lib/seeing_is_believing/debugger.rb', line 17

def stream
  @stream
end

Instance Method Details

#coloured?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/seeing_is_believing/debugger.rb', line 13

def coloured?
  @coloured
end

#context(name, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/seeing_is_believing/debugger.rb', line 20

def context(name, &block)
  if enabled?
    stream << CONTEXT_COLOUR if coloured?
    stream << "#{name}:"
    stream << RESET_COLOUR   if coloured?
    stream << "\n"
    stream << block.call.to_s << "\n" if block
  end
  self
end