Skip to content

Instantly share code, notes, and snippets.

@geoffreyd
Created February 23, 2009 02:31
Show Gist options
  • Save geoffreyd/68759 to your computer and use it in GitHub Desktop.
Save geoffreyd/68759 to your computer and use it in GitHub Desktop.
#Ruby assignment option to assign unless nil
replacement_content = page_contents.content_label_find(item)
element.inner_html = replacement_content if replacement_content
# Should be able to do something like... not sure if the "=||" is the best suggestion for the assignment symbols
element.inner_html =|| page_contents.content_label_find(item)
# I don't think this is quite what you want, but it's a handy little trick:
one = false
two = nil
out ||= one ||= two ||= 3
will return 3, but if 'one' or 'two' are set to something, then the first value that is a non false/nil will be assigned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment