From: "Jesús Gabriel y Galán" Date: 2009-09-18T19:40:50+09:00 Subject: Re: dynamically created functions? On Fri, Sep 18, 2009 at 12:10 PM, Lin Wj wrote: >  def self.developer_options(*args) >    fetch_options({'area'=>'developers','index' => args.first}) >  end > >  def self.priority_options(*args) >    fetch_options({'area'=>'priority','index' => args.first}) >  end > >  def self.status_options(*args) >    fetch_options({'area'=>'status','index' => args.first}) >  end > > is there anyway to dynamically create methods with a specific name ? > > ie: create methods which are > > def self.??????_options(*args) >    fetch_options({'area'=>'?????','index' => args.first}) >  end As Ralf said, you can use define_method. If you want to create them up-front (untested): %w{developer priority status}.each do |area| define_method "#{area}_options" do |*args| fetch_options({'area' => area, 'index' => args.first}) end end Of course this needs to be done in the scope where self is the singleton class of the object (see a recent post about this). If you want to define them lazily, you can use method_missing (untested): def method_missing (meth, *args, &blk) m = meth.match /(.*)_options$/ super unless m define_method meth do |*arguments| fetch_options({'area' => m[1], 'index' => arguments.first}) end end Hope this helps, Jesus.