NetBeans has TextMate style code templates

Saturday - 09 August 08

Since owning a mac, I have been an avid user of TextMate. Therefore I have picked up some of the TextMate shortcuts for Ruby.

I mostly develop on Windows in the workplace (not out of choice) so I use NetBeans as my main Ruby IDE on both platforms. So I was surprised to find NetBeans contains many of the TextMate code template shortcuts (Known as Bundles in TextMate).

Here are some of the most useful ones:

To activate a code template type the shortcut name followed by the ->| (TAB key)

Shortcut Result
rb #!/usr/bin/env ruby -wKU
req require ""
rw attr_accessor :attr_names
rattr_reader :attr_names
w attr_writer :attr_names
eaeach { |1| }
eaieach_index { |1| }
eakeach_key { |1| }
delidelete_if { |e| }
::key => "value",
dodo |1|
end
def def method_name

end
if if condition

end
unless unless condition

end
while while condition

end
until until condition

end
DirDir.glob() { |3| }
FileFile.foreach("path/to/file") { |3| }
beginbegin

rescue Exception => 1
   code
end
claClassName = Struct.new(:attr_names) do
   def method_name
   end
end

Unit Test code templates:

Shortcut Result
tsrequire "test/unit"

require "tc_test_case_file"
require "tc_test_case_file"
tcrequire "test/unit"
require "library_file_name"

class Test < Test::Unit::TestCase
   def test_case_name
   end
end
asassert(test, "Failure message.")
aseassert_equal(expected, actual)
asneassert_not_equal(unexpected, actual)

The main shortcut that is different is 'cla' in NetBeans this creates a new Struct, but in TextMate it gives you a choice of class options.

Fear not! NetBeans lets you add new code templates by going to: Preferences > Editor > Code Templates.

They're loads more unit test code templates too.



Comments:

Paul Taylor | Tuesday - 12 August 08 @ 20:48

Useful stuff Dan. How about a post on naked coding techniques?

Dan Hunter | Tuesday - 12 August 08 @ 22:10

Thanks, good idea! Although you are the master in that field so I could use some tips from the your good self :)

Want to comment?



simple_captcha.jpg
Enter the text of the image above: