module Ricecream
Constants
- ICMethod
- VERSION
Public Class Methods
colorize_code(code)
click to toggle source
# File lib/ricecream/colorize.rb, line 4 def self.colorize_code(code) return code unless @colorize require "irb" unless defined?(IRB::Color) && IRB::Color.respond_to?(:colorize_code) && @output.respond_to?(:tty?) && @output.tty? return code end IRB::Color.colorize_code(code.to_s) end
context(location)
click to toggle source
# File lib/ricecream/ic.rb, line 43 def self.context(location) "#{location.path}:#{colorize_code(location.lineno)} in #{location.label}" end
format(location, name, args)
click to toggle source
# File lib/ricecream/ic.rb, line 15 def self.format(location, name, args) str = prefix(location) arity = args.size if arity == 0 return "#{str}#{context(location)} at #{Time.now.strftime('%H:%M:%S.%L')}" end path = location.absolute_path unless @ic_methods[path] require_relative "analyzer" @ic_methods[path] = Analyzer.new(path).ic_methods end lineno = location.lineno method = @ic_methods[path].find do |m| m.lineno == lineno && m.arity == arity && m.name == name end str += "#{context(location)}- " if @include_context || !method argstrs = method ? method.args.map { |arg| colorize_code(arg) } : 1.upto(arity).map { |i| "<arg#{i}>" } args = args.map { |arg| colorize_code(arg_to_s(arg)) } argpairs = argstrs.zip(args).map do |argstr, arg| argstr == arg ? argstr : "#{argstr}: #{arg}" end str + argpairs.join(", ") end
ic(location, name, args)
click to toggle source
# File lib/ricecream/ic.rb, line 11 def self.ic(location, name, args) output format(location, name, args) if @enable end
Public Instance Methods
ic(*args)
click to toggle source
# File lib/ricecream/refine.rb, line 7 def ic(*args) Ricecream.ic(caller_locations(1, 1).first, :ic, args) return *args end
ic_format(*args)
click to toggle source
# File lib/ricecream/refine.rb, line 12 def ic_format(*args) Ricecream.format(caller_locations(1, 1).first, :ic_format, args) end