params[:id].present?
nil.present?
( the original post was a hack adding String.filled? / NilClass.filled? )
Building web applications and fighting the daily madness
params[:id].present?
nil.present?
( the original post was a hack adding String.filled? / NilClass.filled? )
6 comments
Comments feed for this article
October 19, 2009 at 14:19
Sly
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.
October 19, 2009 at 14:44
pragmatig
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
October 19, 2009 at 15:29
Matt Darby
What you’re looking for is String#present?
October 19, 2009 at 15:46
pragmatig
+1 for mr darby
October 19, 2009 at 16:37
Matt Darby
#present? is awesome. It works for Array too. ([].present? == false)
October 19, 2009 at 19:34
pragmatig
hmm array.filled? reads better imo, but i take what i can get :>