invert



http://docs.ruby-lang.org/en/2.0.0/Hash.html

invert → new_hash
Returns a new hash created by using hsh's values as keys, and the keys as values.


h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 }
h.invert   #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}


 <td class="recommend"><%= subchannel_item.if_recommend %></td>
  RECOMMEND = { 
    '' => false,
    '' => true
  }
  def if_recommend
    RECOMMEND.invert[recommend]
  end


[11] pry(main)> SubchannelItem::RECOMMEND
=> {""=>false, ""=>true}
[12] pry(main)> SubchannelItem::RECOMMEND.invert
=> {false=>"", true=>""}

[15] pry(main)> SubchannelItem::RECOMMEND.invert[SubchannelItem.first.recommend]
=> ""




你可能感兴趣的:(invert)