On Fri, Sep 18, 2009 at 12:10 PM, Lin Wj <mailbox.lwj / gmail.com> wrote:
>   >  ᧽󧬧  
>  
>
>   
>  
>  
>
>   
>  ᧽󧬧  
>  
>
> is there anyway to dynamically create methods with a specific name ?
>
> ie: create methods which are
>
> def self.??????_options(*args)
>  
>  

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.