Skip to content

Instantly share code, notes, and snippets.

@cwoodall
Created July 19, 2011 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwoodall/1091236 to your computer and use it in GitHub Desktop.
Save cwoodall/1091236 to your computer and use it in GitHub Desktop.
blank.rb : Evaluate whether the Object is nil or empty. Makes sure it gets evaluated regardless of empty or nil.
# Evaluate whether the Object is nil or empty. Makes sure it gets evaluated regardless of empty or nil.
#
# Author:: Christopher J. Woodall (mailto:chris.j.woodall@gmail.com)
# Copyright:: Copyright (c) 2011 Christopher J. Woodall
# License:: All Rights Reserverd
# add blank? method to Object
class Object
# Checks for nil? and empty? at once... If one fails move to the other.
def blank?
begin
self.nil? || self.empty?
rescue NoMethodError
self.nil?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment