--005045013dbfbeec7d0486fccf83
Content-Type: text/plain; charset=UTF-8
Well the first thing that I see is that your missing the (*args) in the
method
instance_eval %{
def status_all
"#{args.join(' ')}".split
end
}
Should be
instance_eval %{
def status_all(*args)
"#{args.join(' ')}".split
end
}
On Thu, May 20, 2010 at 06:59, Adriano Nagel <anr / safira.com> 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.
--005045013dbfbeec7d0486fccf83--