Coder Social home page Coder Social logo

better_caller's Introduction

better_caller

Author Tim Morgan
Date Dec 23, 2009
License MIT (see LICENSE.txt for details)

Introduction by example

Actions speak louder than words. Gone are the days of this old suckageness:


caller #=> ["test.rb:8:in `foo'", "test.rb:16:in `<main>'"]

With better_caller, you get this new hotness:


require 'better_caller'
better_caller #=> [["test.rb", 8, :foo, #<Binding:0x000001010cae50>], ["test.rb", 16, :"<main>", #<Binding:0x000001010caef8>]]	

There are a couple of things you may notice. First of all, the okay-that’s-nice
thing: String parsing is a thing of the past. You get the file, line, and method
as separate elements. This happens at the Ruby interpreter level.

Now, the holy-shit-that’s-awesome feature: You get bindings, all the way up
the stack.
Yes, that’s right, you can do this:


eval "local_variables", better_caller.first.last #=> [ :var1, :var2, :foo ]

You also get this stuff in exception, mondo excellent for debugging:


$!.better_backtrace # now you can figure out what your local variables were at the time of the exception!

This is horribly slow, right? You’re using some set_trace_func magic
that’s going to make my Ruby 1,000,000% slower, right?

No. better_caller is a C function that uses the internal Ruby memory structures
to build its output. Absolutely no set_trace_func and no speed hit.

Super ominous alpha warning

better_caller is extremely, hyperbolically alpha right now. Here are some known
obstacles currently preventing it from blowing minds:

  • It only works with a very specific version of Ruby (in particular,
    1.9.2-p136).
    This is because it uses some private Ruby C functions to work
    its magic, so it keeps a copy of some header files that you’re not really
    supposed to be using.
  • Storing local variables in exceptions isn’t quite working yet. Hopefully
    I’ll have a fix soon; be patient.

Despite that, it does work sometimes, and when it does, I think it rocks. If you
do too, please do me the honor of contributing to this project, especially if
you’re one of the three people on the planet that understand the workings of
Ruby frame pointers. That would be swell.

Additional to-do items

  • Comments
  • Some way of doing specs?

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.