From: Robert Klemme Date: 2009-01-10T03:09:39+09:00 Subject: Re: Using a method as input to another method On 09.01.2009 18:48, Erick Star wrote: > Hi, I was wondering if it was possible to do something like the > following: > > class A > > def b > stuff > end > > def c > stuff > end > > def d(x) > self.x > end > end You can leave out method d and use send() directly, i.e. a = A.new a.send(:b) However: > Then use thing.d(a) with thing an instance of A? > Basically, given a long list of methods belonging to a class, if you > wanted ruby to apply methods based on the state of the program, how > would you set it up besides doing: > > case A > when b > thing.stuff > when c > thing.otherstuff State pattern comes to mind. http://en.wikipedia.org/wiki/State_pattern There are a number of options for modeling this besides of state pattern. Generally any OO approach exploits overriding of methods, i.e. you have several classes which share a method with identical signature but different behavior. Kind regards robert -- remember.guy do |as, often| as.you_can - without end