Class: SeeingIsBelieving::Debugger

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

Constant Summary collapse

CONTEXT_COLOUR =
"\e[37;44m"
RESET_COLOUR =
"\e[0m"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Debugger

Returns a new instance of Debugger.



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

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.



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

def stream
  @stream
end

Instance Method Details

#coloured?Boolean

Returns:

  • (Boolean)


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

def coloured?
  @coloured
end

#context(name, &block) ⇒ Object



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

def context(name, &block)
  if stream
    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