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:TwitterLinkedInPocketMoreEmailFlattrPrintRedditTumblrLike this: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 :>