From: "rogerdpack (Roger Pack)" Date: 2012-07-14T15:39:04+09:00 Subject: [ruby-core:46421] [ruby-trunk - Feature #6731] add new method "Object.present?" as a counter to #empty? Issue #6731 has been updated by rogerdpack (Roger Pack). File present.txt added Adding "presentation" txt file. ---------------------------------------- Feature #6731: add new method "Object.present?" as a counter to #empty? https://bugs.ruby-lang.org/issues/6731#change-28042 Author: rogerdpack (Roger Pack) Status: Open Priority: Normal Assignee: Category: Target version: Basically Object#present? , "An object is present if it���s not #empty?" [2] or, in other words, "is there any data inside?" Examples: >> [].present? => false >> [3].present? => true >> ''.present? => false # because it's #empty? >> 'a'.present? => true >> nil.present? => false Example usage: button.text=text if text.present? # I only care whether the text actually was set to something, and also don't want to worry about whether it's nil or not. Thanks. Basic implementation ([1]): class Object def present? !(respond_to?(:empty?) ? empty? : !self) end end [1] http://stackoverflow.com/a/4649452/32453 [2] http://api.rubyonrails.org/classes/Object.html#method-i-present-3F they also use #blank but that's for a different feature request. -- http://bugs.ruby-lang.org/