From: Adriano Nagel Date: 2010-05-20T12:24:23+09:00 Subject: Re: define_method inside instance_eval Dhruva Sagar wrote: > 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 Actually, args already is an array and you don't need it as an argument for status_all (it was passed to status_field). But the problem here is that this will produce an instance method, not a class method. > 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 ? I'm extending ActiveRecord, and status_field does more than just define status_all. For example: class User < ActiveRecord::Base status_field :inactive, :active, :suspended end will create scopes, instance methods like status_inactive, status_inactive?, etc. User.status_all should return all the possible user status. I have it working, but I would like to learn a better way to do it. Thanks, -- Adriano -- Posted via http://www.ruby-forum.com/.