Rubyize this : 2nd edition
Get ready for another edition of Rubyize this
Short informative posts, to the point.
Get ready for another edition of Rubyize this
The following is easy stuff but we tend to forget about it… probably because most of us are not used to this kind of behavior from a programming language.
It’s not a secret, Ruby syntax offers many possibilities. One thing I enjoy doing once in a while is to take some code I have written a few days before and improve it to make it look more rubyish (read : short, expressive and readable). I thought it could be fun to make a little […]
Enumerations are an elegant way to make your code more readable. Unfortunately, Ruby doesn’t have a built-in enum type. (Don’t stop reading now! This story ends with hapiness and joy)
To access a class method from an instance, you have to use the reference to that class (because that’s where the method resides). The attribute reader that returns that reference is named class
If you come from another language, you might be tempted to use the += operator when appending to a string.
Sometimes, you want to initialize a variable to some value only if that variable is equal to nil. If you like to write your methods as short, clean and readable as possible, you can do that task in a single line instead of taking the traditionnal 3 lines approach.
Unlike many other languages, 0 isn’t qualified as false in an expression.