Ruby on Rails Tuesday, April 25, 2017

On Tue, Apr 25, 2017 at 4:18 PM, Walter Lee Davis <waltd@wdstudio.com> 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 ------------------------ hassan.schroeder@gmail.com
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.

No comments:

Post a Comment