The opposite of Rails blank? is present?

params[:id].present?
nil.present?

( the original post was a hack adding String.filled? / NilClass.filled? )

Advertisements

6 thoughts on “The opposite of Rails blank? is present?

  1. 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.

  2. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s