Apr 16 2008

TextMate: Execute Inline Ruby

Published by at 7:02 am under TextMate

  

When working in TextMate, if you have a one or more lines of Ruby code that you would like to have the interpreter run, without the need for passing the entire file to the interpreter, this tip may be just what the doctor ordered.

For example, when debugging, often times it would be really handy to run a simple script at a specified location in your code to look at a value, call a method on an Object… The key point here is that you can have as little as one line of Ruby processed by the interpreter and the return value will be inserted inline.

This easiest way to get the gist of this is to watch the screencast below:

If you want to insert the results of one or more lines of script, directly into your code, using # => markers is the way to go.




The music in the video is J.J. Cale and the song: Call Me the Breeze.

A longer clip of J.J. Cale jamming: [audio:/2008/jj.mp3]

6 responses so far

6 Responses to “TextMate: Execute Inline Ruby”

  1. edon 01 May 2008 at 10:06 am

    Is the video offline? All I see is a white, then black screen with no sound.

  2. johnon 01 May 2008 at 10:10 am

    The video should popup in a new window. Do you see the popup window in your browser? The movie is in the QuickTime format, so depending on your system/browser (e.g. non Mac), you may need to install a plugin.

  3. alexon 13 May 2008 at 6:15 am

    I’m using Mac OS X and, just like ed, I can see only a white, with movie cursor advancing.

  4. johnon 13 May 2008 at 6:37 am

    Can you try a different browser and let me know if that works? Also, if you follow the link below that should open the movie (without a popup window):

    http://macdevelopertips.com/wp-content/uploads/2008/04/TextMateTip-001-execute-markers.mov

    Let me know if that works any better (if so, might be time to ditch the popup window approach).

  5. vwon 17 May 2008 at 9:08 pm

    I got the blank movie as well. By scrubbing the timeline (eg. moving the playhead back to the beginning), the movie started playing normally.

  6. Jeff Powellon 27 May 2008 at 4:07 pm

    This is a fantastic tip. I work in Ruby quite a bit via TextMate and had never explored this option but it is incredibly useful! Thanks a ton!