Skip to content

Instantly share code, notes, and snippets.

@yyalim
Last active November 2, 2015 11:23
Show Gist options
  • Save yyalim/91d3bdac7d4b5d300de7 to your computer and use it in GitHub Desktop.
Save yyalim/91d3bdac7d4b5d300de7 to your computer and use it in GitHub Desktop.
Trick to handle no method error on nil objects
"hello world".upcase
# => "HELLO WORLD"
nil.upcase
# NoMethodError: undefined method `upcase' for nil:NilClass
# "gem install activesupport" if it is not installed
require 'active_support/core_ext/object/blank'
nil.presence && nil.upcase
# => nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment