📎 Webclip
Ruby Gotchas that will come back to haunt you
The page gathers common Ruby pitfalls and recommends habits that avoid confusion and bugs. It focuses on places where Ruby does something different from what many developers expect, especially in control flow, comparison, inheritance, scope, and method visibility.
Reading notes#
and / ordo not behave like&& / ||; the keyword versions have lower precedence, so the safe practice is to use only&& / ||.eql?,equal?, and===are different from==; the page recommends using==unless there is a specific reason to compare differently.superwithout parentheses passes the original method arguments to the parent method, whilesuper()calls the parent with no arguments.- Custom exceptions should inherit from
StandardErroror a descendant, andrescue Exceptionshould be avoided. class Foo::Bardoes not create the same lexical scope asmodule Foo; class Bar; the longer nested form keeps access to constants from the enclosing module.- Many
bang!methods returnnilwhen they make no change, so their return value should not be used in conditionals or control flow. - An assignment method like
attribute=(value)returns the assigned value, not the explicit return value from inside the method. privatedoes not makeself.methodprivate; useprivate_class_methodor define the method insideclass << self.- The closing note says these issues can look minor at first, but they can create serious headaches during Ruby on Rails development.
