From: John Lane Date: 2010-04-16T18:21:22+09:00 Subject: Re: Blocks and local variable creation Robert Dober wrote: > I do not reallly understand why you want nil, instead of [], but apart > of this I would do > select{|_,v| v.include? item}.map(&:first) > > or if you insist > > inject( nil ){ |r,(k,v)| v.include?( item ) ? (r||[]) << k : r } Can you please explain the line: > select{|_,v| v.include? item}.map(&:first) I've never seen the _ before where I would expect a variable. I also don't understand (&:first) on the call to map. The reason I was returning nil was so I can the write code like this: rights_held = rights_for_item (rights_hash, item) perform_something_with_rights unless rights_hash.nil? perhaps I should change that thought process to this: rights_held = rights_for_item (rights_hash, item) perform_something_with_rights unless rights_hash.empty? I had thought use of nil was the right way but I'm learning so I'm happy to be convinced otherwise... -- Posted via http://www.ruby-forum.com/.