Sha256: f90a895fc89ab332d52faced8c90a9084515974f3fbe29f8a69af5590013861d

Contents?: true

Size: 911 Bytes

Versions: 2

Compression:

Stored size: 911 Bytes

Contents

module Cutter
  class Inspection
    class << self
      def quiet!
        @quiet = true
      end

      def loud!
        @quiet = nil
      end

      def quiet?
        @quiet
      end
    end
  end
end

class Object
  # For now inspect! method only may be used with two arguments (local_variables, binding)
  # Binding is a Ruby class: http://www.ruby-doc.org/core/classes/Binding.html
  
  def inspect! _binding = nil, &block
    return true if Cutter::Inspection.quiet?
    raise "Try binding as argument or wrap method content into block!" if (!block_given?&&!_binding)
    _binding ||= block.binding
    puts "method: `#{caller_method_name}'"
    puts %{  variables:} 
    eval('local_variables',_binding).map do |lv|
      puts %{    #{lv}: #{eval(lv.to_s, _binding)} } 
    end
    yield if block_given?
  end

  def caller_method_name(level = 1)
    caller[level][/`([^']*)'/,1].to_sym
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cutter-0.5.1 lib/cutter/inspection.rb
cutter-0.5.0 lib/cutter/inspection.rb