Class: Object

Inherits:
BasicObject
Defined in:
lib/ctx.rb

Instance Method Summary collapse

Instance Method Details

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



33
34
35
36
37
38
39
40
41
# File 'lib/ctx.rb', line 33

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

#ctxp(*args) ⇒ Object



26
27
28
29
30
# File 'lib/ctx.rb', line 26

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

#ctxputs(*args) ⇒ Object



21
22
23
24
25
# File 'lib/ctx.rb', line 21

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

#symObject



20
# File 'lib/ctx.rb', line 20

def sym() respond_to?(:to_sym) ? to_sym : to_s.to_sym end