From: Dhruva Sagar Date: 2010-05-20T11:38:46+09:00 Subject: Re: define_method inside instance_eval --0016367d6dec20c2840486fd7871 Content-Type: text/plain; charset=UTF-8 Ok I reread your problem. In your status_all method you can simply return a *args.to_a*. That should be the simplest approach. def status_field(*args) instance_eval { define_method(:status_all) {|*args| args.to_a } } end But I am not sure exactly why your taking this approach or what your intentions are. What should be the behavior on subsequent calls to status_field ? On Thu, May 20, 2010 at 06:59, Adriano Nagel wrote: > Hi, > > I'm trying to create a class macro that, when called, defines a class > method that returns the array passed to the class macro. > > For example, I'd have something like this in an included module: > > def status_field(*args) > instance_eval { define_method(:status_all) { args } } > end > > (I've put a complete example at http://gist.github.com/407035). > > I was under the impression that methods created inside instance_eval > would be defined inside the singleton class, but apparently > define_method seems to ignore that (why?). > > So I used the string form of instance_eval and produced this eyesore: > > instance_eval %{ > def status_all > "#{args.join(' ')}".split > end > } > > I must be missing something. Any hints on how to solve this problem > properly? I'd also like to avoid using eval on strings. > > Thanks! > > -- > Adriano > -- > Posted via http://www.ruby-forum.com/. > > -- Thanks & Regards, Dhruva Sagar. --0016367d6dec20c2840486fd7871--