From: kushcs@... (Christopher S. Kush) Date: 2001-12-06T13:52:06+09:00 Subject: [ruby-talk:27609] Emulating multimethods Okay, I'm writing my first Ruby code *ever* today, so go easy on me. I want to write a class that emulates a piece of hardware. The hardware spec I'm working from says that the Hardware reacts to different Inputs differently, depending on its State. Now, in CLOS, I could write multimethods and the runtime would just handle everything. But Ruby doesn't have that (yet (hint, hint)), so I came up with the following: class Hardware def crunch_input_X_in_state_Y( x, y ) @input = x @state = y self.send( "crunch_input_" + x.name + "_in_state_" + y.name ) end def crunch_input_Foo_in_state_Sleeping # mess with stuff end def crunch_input_Bar_in_state_Happy # mess with stuff end end