TextMate, Ruby & String Interpolation

While preparing some code example for the Euruko 2007 I noticed a somewhat strange behaviour of TextMate while editing Ruby code. With the Ruby bundle being active, I expect CMD-R (“Apple-R”) to execute the Ruby code a hand. Which it does, unless the text cursor is inside a string interpolation expression.

An example: The first screen shot shows the example code, the cursor being positioned outside the #{ … }.

cursor_outside_srint_interpol.png

After CMD-R is hit, the output is the expected Ruby output as shown below.

outside_result.png

However, if the cursor is inside the string interpolation expression as below

cursor_inside_print_interpol.png

the result of hitting CMD-R doesn’t meet my expectation:


inside_result.png

I wonder why this happens. Apparently the behaviour has to do the the scope the cursor is in. A hint about how to avoid this is greatly appreciated.

Advertisements

3 thoughts on “TextMate, Ruby & String Interpolation

  1. Okay, here is a quick fix:

    The scope of #{…} is:
    source.ruby.embedded.source

    The scope selector for Run is:

    source.ruby – source.ruby.embedded

    (on every ruby-source that is not embedded)

    If you delete “- source.ruby.embedded”, this works well. The problem is: now you have this command vor every embedded source (ERB, etc.).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s