From: Marnen Laibow-Koser Date: 2009-11-20T03:29:14+09:00 Subject: Re: Ternary Operator and Arrays Felix Dominguez wrote: > Given: > ary = Array.new > some_hash = {'a' => 1, 'b' => 2, 'c' => 3} > another_array = ['a', 'c'] > > Then: > another_array.each do |x| > ary << some_hash.has_key?(key) ? ' ' : some_hash[key] > end > > Expected: > ary should be [1, ' ', 3] > > Actual: > [true, false, true] > > Question: > Why does that happen? > > -Felix It's probably a precedence issue. Looks like << is binding tighter than ?: . Anyway, you can just do ary = another_array.collect{|x| some_hash[x] || ' '} Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.