Class: Object

Inherits:
BasicObject
Defined in:
lib/ctx.rb

Instance Method Summary collapse

Instance Method Details

#ctx(context = :anonymous, &contextual) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/ctx.rb', line 26

def ctx(context = :anonymous, &contextual)
  if contextual.nil?
    @@contexts.first
  else
    @@contexts.unshift(Context.new(context))
    instance_eval(&contextual)
    @@contexts.shift()
  end
end

#ctxp(*args) ⇒ Object



19
20
21
22
23
# File 'lib/ctx.rb', line 19

def ctxp(*args)
  ctxs = @@contexts.map(&:name)[1..-1].reverse.join(":")
  ctxs = "[CTX #{ctxs.empty? ? "-" : ctxs}]"
  puts "#{ctxs}\n#{args.map(&:inspect).join("\n")}"
end

#ctxputs(*args) ⇒ Object



14
15
16
17
18
# File 'lib/ctx.rb', line 14

def ctxputs(*args)
  ctxs = @@contexts.map(&:name)[1..-1].reverse.join(":")
  ctxs = "[CTX #{ctxs}] " unless ctxs.empty?
  puts "#{ctxs}#{args.map(&:to_s).join(', ')}"
end