Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Common ruby patterns

mjgiarlo edited this page Apr 13, 2012 · 3 revisions

This will help you See The Light of the glory and beauty of Ruby.

To set a variable based on the condition of a value in another variable, use this pattern:

@var = other_var || "default value"

instead of this one:

if other_var
  @var = other_var
else
  @bar = "default value"
end

and if the other value might be coming from a Hash, use this:

@var = my_hash.fetch("other_var", "default value")
Clone this wiki locally