A
Adriano Nagel
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_methodstatus_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!
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_methodstatus_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!