Ruby : Anomality : Empty array is not always considered false

35: def flash_message(flash)
 36: matched_keys = flash.keys & [:notice, :error, :alert, :warning]
 37: if matched_keys
 38: 
 39: usable_key = matched_keys.last.to_s rescue 'notice'
 40: message = flash[:notice] || flash[:error] || flash[:alert] || flash[:warning]
 => 41: binding.pry
 42: 
 43: <<-HTML
 44: <div class="jquery-notify-bar always-on-top #{usable_key}-message #{usable_key} top">
 45: <span class="notify-bar-text-wrapper">#{message}</span>
 46: <a href="#" class="notify-bar-close">Close [X]</a>
 47: </div>
 48: HTML
 49: end
 50: end

And when I checked the values I am amazed

[1] pry(#<#<Class:0x007fd86c665340>>)> matched_keys
=> []
[2] pry(#<#<Class:0x007fd86c665340>>)> matched_keys == true
=> false
[3] pry(#<#<Class:0x007fd86c665340>>)> matched_keys
=> []
Ruby Acting unexpected

Ruby Acting unexpected

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