Created
July 19, 2011 03:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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