I have a class Foo
which has several methods like button_0_0
, button_0_1
, button_0_2
, button_1_0
, etc.
I would like to be able to access these alternatively via the following syntax:
foo.button[0][1]
foo.button[1][2]
# etc.
I know I could just create a @button
instance variable and iterate through all the button_*
accessors and add them that way, but that seems a bit kludgy and doesn't really follow the "ruby way" of doing things.
I was wondering if there was a more succinct, Rubyish solution to this problem (maybe by using method_missing
?)—Does anyone know a better way of doing this?
(I've figured this out partway, but I get stuck at the square brackets because []
calls a new method on the missing method...)