Module: Kernel

Defined in:
lib/bruce-banner.rb

Overview

this is where the magic happens…

Instance Method Summary collapse

Instance Method Details

#bb(what = "", options = {}, &block) ⇒ Object

block magic shamelessly stolen from Jim Weirich (with a small tweak) www.justskins.com/forums/print-out-a-variables-101209.html



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bruce-banner.rb', line 48

def bb(what="", options={}, &block)
  options = BruceBanner.defaults.merge(options)

  if block_given?
    name = block.call.to_s
    what = "#{name}: #{eval(name, block.binding)}"
  end

  if options[:size_to_fit]
    options[:count] = [what.to_s.size, BruceBanner.defaults[:maximum]].min
  end

  output = []
  output << (options[:string] * options[:count]) if options[:before]
  output << "#{what}"
  output << (options[:string] * options[:count]) if options[:after]
  
  puts output.join("\n")
end