Ruby on Rails
Tuesday, April 25, 2017
On Tuesday, April 25, 2017 at 7:27:25 PM UTC-4, Hassan Schroeder wrote:
On Tue, Apr 25, 2017 at 4:18 PM, Walter Lee Davis <wa...@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.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
Thanks
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/4272df64-fcf7-4abe-8037-7790777faa62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment