On Tue, Apr 25, 2017 at 4:18 PM, Walter Lee Davis <[email protected]> wrote:

> But in an array, you're going to have to iterate to find it:
>
> def name_for_code(code)
>   ADDRESS_STATE_TYPES.each do | pair |
>     return pair.first if pair.last == code
>   end
> end

or e.g.

2.3.3 (main):0 > types = [['Alabama','AL'],['California','CA']]
=> [
  [0] [
    [0] "Alabama",
    [1] "AL"
  ],
  [1] [
    [0] "California",
    [1] "CA"
  ]
]
2.3.3 (main):0 > types.to_h.invert.dig("CA")
=> "California"
2.3.3 (main):0 >

-- 
Hassan Schroeder ------------------------ [email protected]
twitter: @hassan
Consulting Availability : Silicon Valley or remote

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yBz-wRPMY7HUx2Dw_9VqAb3vwjU-Pbn06FRtRf%3D2i5Ltw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to