Module: Q

Defined in:
lib/qp/q.rb

Class Method Summary collapse

Class Method Details

.p(*args, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/qp/q.rb', line 3

def self.p(*args, &block)
  callable = block || args[0]

  if callable.respond_to?(:yield)
    source = callable.source.strip if RUBY_VERSION[0].to_i >= 2
    
    puts "#{source} -> #{callable.yield}"
  else
    if RUBY_VERSION[0].to_i >= 2
      cl = caller_locations[0]

      source = File.readlines(cl.path)[cl.lineno-1].strip
    end

    puts "#{source} -> #{args.join(',')}"
  end
end