[ ruby ] .any?

Passes each element of the collection to the given block. The method returns true if the block ever returns a value other than false or nil

%w{ant bear cat}.any? {|word| word.length >= 3} #=> true

ref : http://apidock.com/ruby/Enumerable/any%3F

Avoid undefine method on Nil

@myvar = session[:comments].try(:[], @comment.id)

It is like “@myvar = session[:comments][@comment.id]”.

ref : http://stackoverflow.com/questions/6224875/equivalent-of-try-for-a-hash-to-avoid-undefined-method-errors-on-nil


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s