From: Albert Schlef Date: 2008-05-02T22:05:50+09:00 Subject: Re: Extracting a value from an array Thanks you all for these snippets. However, the snippets you gave me may fail, because there's one detail I neglected to mention --as I thought it was obvious from my code: The 'content-type' header may be missing. That's because servers don't always return it: in '302 redirect' replies there isn't a 'content-type' at all. The problem with the snippets I was given here is that they unconditionaly do [:value] on some expression. When the 'content-type' is missing, the expression is 'nil', and since the [] method isn't defined for NilClass, the code fails with an exception. I know I can change your "some_expression.first[:value]" to "(some_expression || {}).first[:value]" and then things would work. OK. But I wondered if there's some nifty solution. I don't mind seeing a Ruby 1.9 only solution (or a Ruby 2.0 one) --though I'm using 1.8, this question is mostly to satisfy my curiosity. -- Posted via http://www.ruby-forum.com/.