Ruby is a really nice language. It's very easy to learn and get started in, and you will be productive extremely quickly, but to actually master the language takes much time. I think this is underestimated in many circles. Ruby uses lots of language constructs which are extremely powerful, but they require you to shift your thinking - especially when coming from Java, which many current Ruby converts do.
As a small example of a gotcha, what does this code do:
class FooIf your answer is that it prints 42, you're wrong. It will print nil. What's the necessary change to fix this? Introduce self:
attr_accessor :bar
def initialize(value)
bar = value
end
end
puts Foo.new(42).bar
class FooYou could argue that this behavior is annoying. That it's bad. That it's wrong. But that's the way the language works, and I've seen this problem in many code bases - including my own - so it's worth keeping an eye open for it.
attr_accessor :bar
def initialize(value)
self.bar = value
end
end
puts Foo.new(42).bar
Why does it happen? Well, the problem is this, when the Ruby parser finds a word that begins with an underscore or a lower case letter, and where that word is followed by an equals sign, there is no way for the parser to know if this is a method call (the method foo=) or a variable assignment. The fall back of the parser is to assume it is a variable assignment and let you specify explicitly when it should be a VCall. So what happens in the first example is that a new local variable called "bar" will be introduced and assigned to.
