Rubymine print current line

Posted by Jason Noble on 01/28/2012 in Uncategorized |

One way of debugging your ruby scripts is to print out the value of variables in different sections of your code.

Rubymine has a feature called live templates that allows you to type a short command and have RubyMine extract it in to full blown code. Some built in shortcuts exist, such as def (creates a method), desc (create a RSpec test), it (RSpec test), etc.

To create your own, go to RubyMine -> Preferences -> Live Templates. Click one of the existing templates and hit Copy.

I named mine pl (Put Line Number) and put the following content in:

puts “#{__FILE__:#{__LINE__}”

Now when I’m typing code, I can hit the following:

pl<TAB>
p “Hello”

And it will print out the following:

/Users/jasonn/source/project/junk.rb:1
“Hello”

I’ve found this helpful for tracking down where a specific print statement is located.

Copyright © 2008-2024 Jason Noble's Technical Adventures All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.