The opposite of Rails blank? is present? params[:id].present? nil.present? ( the original post was a hack adding String.filled? / NilClass.filled? ) Share this: Share on X (Opens in new window) X Share on LinkedIn (Opens in new window) LinkedIn More Email a link to a friend (Opens in new window) Email Share on Flattr (Opens in new window) Flattr Print (Opens in new window) Print Share on Reddit (Opens in new window) Reddit Share on Tumblr (Opens in new window) Tumblr Like Loading... Related
Why not using “any?”. Sure, you’d have to add the definition to NilClass, but it makes sense. For Strings, Arrays and Hashes, however, it is already defined. Reply
never thought that any? is defined for String, its a good alternative to filled? (especially if you do not want to hack String), but I still prefer params[:name].filled? over params[:name].any? out of pure readability Reply
Why not using “any?”.
Sure, you’d have to add the definition to NilClass, but it makes sense.
For Strings, Arrays and Hashes, however, it is already defined.
never thought that any? is defined for String, its a good alternative to filled? (especially if you do not want to hack String), but I still prefer params[:name].filled? over params[:name].any? out of pure readability
What you’re looking for is String#present?
+1 for mr darby 😀
#present? is awesome. It works for Array too. ([].present? == false)
hmm array.filled? reads better imo, but i take what i can get :>