Making rbeautify.rb work with SciTE

I really like Paul Lutus’ Ruby Beautifier but it does not display properly in SciTE because it is missing the tabs on blank lines. Luckily its really easy to fix.

BROKEN - SciTE with tabs missing:
Scite with no tabs on blank lines

FIXED - SciTE with tabs in place:
Ruby file with Tabs on Blank Lines

Assigning RegEx brackets into variables with Ruby

Ruby has the ability to reference the last RegEx used and extract portions of it to assign to variables.

Define a new search:
[sourcecode language='ruby']
line = “foo==>to the bar”
rx = Regexp.new(/(.*)(\=\=\>)(.*)/) # each bracket can be assigned to a variable

rx.match(line)

head = Regexp.last_match(1) # foo
middle = Regexp.last_match(2) # ==>
tail = Regexp.last_match(3) # bar
[/sourcecode]

you could also also use this by streamlining it in an if statement.
[sourcecode language='ruby']
line = “foo==>to

Posted at 9pm on 09/08/08 | no comments | Filed Under: regex, ruby read on