Giter VIP home page Giter VIP logo

puppy-evil's Introduction

Puppy Gem Version

Puppy is a tiny gem which will help you to perform easy object tracing and debugging.
It simply defines a trace instance method on the Object class, once this method is invoked on an object of any kind, Puppy will start following and tracing like there's no tomorrow! :D

Methods

Basically the only method that you are going to use is trace defined on every Object derived class, which can be invoked with a set of options and with an optional code block to perform conditional tracing, original object instance, method and arguments list are passed to the code block.

Options are:

  • :as - how to represent the instance as string, if a Symbol is given it will be invoked as a method, otherwise as a string. Default: :class
  • :caller - a boolean to enable or disable printing caller data. Default: true
  • :step - if true stop the execution on each method invoked and wait for the user to press a key. Default: false
  • :indent - if true method invocations will be indented as their nesting goes deeper. Default: true
  • :stream - the stream to use to print the report while tracing the object, must overload the << operator. Default: STDERR

Examples

Basic usage.

foo = 1.trace
puts foo

Output:

# Fixnum.to_ary() [puppy.rb:71:in `puts'] 
# Fixnum.respond_to?(:to_ary) [puppy.rb:71:in `puts'] 
# Fixnum.to_s() [puppy.rb:71:in `puts'] 
1

Follow the object without reporting the caller and represent it using its variable name instead of its class.

bar = "something".trace :as => 'bar', :caller => false
puts bar

Output:

# bar.to_ary() 
# bar.respond_to?(:to_ary) 
# bar.to_s() 
something

Use a block to conditionally trace only when arguments list is filled with something.

count = 3.trace { |object,method,*args| args.size > 0 }
puts count.size    # this won't be traced
puts count.to_s(2) # this will

Installation and Usage

You can verify your installation using this piece of code:

gem install puppy

And

require 'puppy'
1.respond_to? :trace

License

Released under the BSD license.
Copyright © 2013, Simone Margaritelli

http://www.evilsocket.net/ All rights reserved.

puppy-evil's People

Contributors

evilsocket avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.