On Thu, Jan 7, 2010 at 10:20 AM, Jagadeesh <mnjagadeesh / gmail.com> wrote:
> hi Gurus,
>
> Here my data structure
>
> 1234 => { 'open' => '1234-1',
> 'analyzed' => '1234-2',
> 'feedback' => '1234-3',
> 'closed' => '1234-4'
> }
> 3455 => { 'open' => '3455-1',
> 'analyzed' => '34552',
> 'feedback' => '3455-3',
> 'closed' => '3455-4'
> }
>
> My task is to display numbers [like 1234 or 3455] if they have ('open'
> OR 'analyzed') AND ('closed' OR 'feedback')   > code
>
> puts numbers if $DATA[pr].has_key?( ( ('closed' || 'feedback')
> && ('open' ||
> 'analyzed') ) )
>
> I am not sure what is wrong with it but its not testing these
> conditions and printing all numbers. Please help me understanding
> has_key method and writing correct condition.

The has_key? method receives a single key to be checked in the hash.
In your snippet, what you are passing to the has_key? method is the
result of evaluating this:

( ('closed' || 'feedback') && ('open' || 'analyzed') )

which is:

irb(main):002:0> ( ('closed' || 'feedback') && ('open' || 'analyzed') )
=> "open"

So you are testing only for the "open" key. I don't know what $DATA or
pr or numbers are in your snippet, but you are testing only for the
key "open".

Hope this helps,

Jesus.