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: Click to share on X (Opens in new window) X Click to share on LinkedIn (Opens in new window) LinkedIn Click to share on Pocket (Opens in new window) Pocket More Click to email a link to a friend (Opens in new window) Email Click to share on Flattr (Opens in new window) Flattr Click to print (Opens in new window) Print Click to share on Reddit (Opens in new window) Reddit Click to 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 :>