N
Nikolai Weibull
I’d like to have a def that I can scope in one go, i.e.,
class A
scoped_def rivate, :a do
â‹®
end
end
at least until we get decorators in Ruby. The following seems to work:
class Class
def scoped_def scope, name, &blk
if [ublic, rotected, rivate].include? scope
define_method name, &blk
self.send scope, name
else
raise ArgumentError, "illegal visibility: %s", scope
end
end
end
I was wondering if anyone has any comments regarding this solution.
Would it be better to put it in Object (wrapping it in a class_eval)
and, if so, why?
Thanks,
nikolai
class A
scoped_def rivate, :a do
â‹®
end
end
at least until we get decorators in Ruby. The following seems to work:
class Class
def scoped_def scope, name, &blk
if [ublic, rotected, rivate].include? scope
define_method name, &blk
self.send scope, name
else
raise ArgumentError, "illegal visibility: %s", scope
end
end
end
I was wondering if anyone has any comments regarding this solution.
Would it be better to put it in Object (wrapping it in a class_eval)
and, if so, why?
Thanks,
nikolai