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 <[email protected] > <javascript:>> 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] > <javascript:> > 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 [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/4272df64-fcf7-4abe-8037-7790777faa62%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

