From: "David A. Black" Date: 2009-07-29T19:46:40+09:00 Subject: Re: instance_eval Hi -- On Wed, 29 Jul 2009, Abhishek Singh wrote: > def method_missing(method_name,*args) > for @@y in(0..@@e-1) do > if ("#{method_name}"==@@a[0][@@y]) > @@index=@@y > break > else if (@@y==@@e-1) > puts "This method (#{method_name})does not belong to any field > value .. !!" > end > end > end > instance_eval " def #{method_name}; puts '#{@@a[@@x][@@index]}'; end" > end > > and when i want to access this newly defined method i'm doing > following:- > > ro1=RecordOne.find("subject","algorithm") > ro1.author > ro1.author > > i'm not able to get value at single method call...:( A typical pattern is to redefine the method and then call it using send: class C def method_missing(m,*args,&block) instance_eval "def #{m}; puts 'In new method!'; end" send(m) end end C.new.blah # In new method! In your case that might look something like this (untested): def method_missing(method_name,*args) index = @@a[0].index(method_name) if index instance_eval <<-EOM def #{method_name} puts #{@@a[@@x][index]} end EOM send(method_name) else super end end I don't know what all the class variables are for, and I've tried to eliminate the ones that seem to be serving only as local variables. David -- David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com Q: What's the best way to get a really solid knowledge of Ruby? A: Come to our Ruby training in Edison, New Jersey, September 14-17! Instructors: David A. Black and Erik Kastner More info and registration: http://rubyurl.com/vmzN