From: Patrick Doyle Date: 2008-09-20T11:11:21+09:00 Subject: Re: [QUIZ] One-Liners Mashup (#177 again) > Given the class: > > class Data2D > def initialize > @data = [ ] # in row major form > end > > def add_row(*row) > @data << row > end > end > > And this setup for an object: > > data = Data2D.new > data.add_row(1, 2, 3, 4) > data.add_row(5, 6, 7, 8) > > Define a [] method for the class that makes this form of access possible: > > x = 2 > y = 1 > data[x][y] # => 7 > How about def [](i) @data.map {|row| row[i]} end >> Post your solution AND a followup problem for others to solve. Oops, I'll have to think about that... but not tonight ... on a completely different topic... I've noticed that whenever I post a message to ruby-talk@ruby-lang.org from my gmail account, I get the message twice in my inbox, making me wonder three things... 1) Does everybody get my messages twice? If so, I humbly apologize and will stop posting immediately as I can see where this could be just a tiny little bit annoying. 2) Does anybody else have this problem? If so 3) How did you solve it (assuming it's a solvable problem)? --wpd