From: Wilson Bilkovich Date: 2006-10-21T06:59:08+09:00 Subject: Re: multi dim array? On 10/20/06, Gijs Nijholt wrote: > Hi (again), > > I have a multi-dimensional array.. walking through an incoming string > like this: > > def translate(msg) > some_alphabet = [ ["a","A"], ["b","B"], ["c","C"], ["d","D"] ] > msg.split(//).inject("") { |result, char| > result += some_alphabet[2][1] > } > end > > This replaces everything in msg with a "C", as it's the third one in the > array. > But I'm looking for a way to replace not by integer/index but by char, > like: > > some_alphabet["c"][1] > > I hope you know what I mean.. I looked at at() and find() and scan() but > neither seems to fit this task? > Does: some_alphabet.detect {|e| e == "c"}[1] ..do what you're looking for?