Monday, June 1, 2009

Common Ruby and JRuby Pitfalls

Not an extensive list yet, but here are some common pitfalls in Ruby/JRuby:

Problem: Can't find a gem/class even in IRB
Solution: Need include 'rubygems'

Problem: uninitialized constant Logger
Solution: Need include 'logger'

Problem: uninitialized constant (constant)
Solution: was not requiring right file. For example: if constants are defined in a file /lib/something/messages.rb, then you need a require 'lib/something/messages'

Problem: unexpected end-of-file
Solution: make sure you have enough "end"s for your "do"s, and be sure you don't have an inappropriate do, like a do after an if.

No comments: