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
2009-10-19 at 14:19:55
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.
2009-10-19 at 14:44:15
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
2009-10-19 at 15:29:38
Matt Darby
What you’re looking for is String#present?
2009-10-19 at 15:46:14
pragmatig
+1 for mr darby
2009-10-19 at 16:37:46
Matt Darby
#present? is awesome. It works for Array too. ([].present? == false)
2009-10-19 at 19:34:25
pragmatig
hmm array.filled? reads better imo, but i take what i can get :>