Skip to content

Instantly share code, notes, and snippets.

@cwoodall cwoodall/blank.rb
Created Jul 19, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.