Permalink
Browse files

optimize eval in module.rb

  • Loading branch information...
1 parent 2379d73 commit d0b4061e201a577db577e628cbe14236d14eba37 @quix committed Jul 20, 2009
Showing with 13 additions and 5 deletions.
  1. +13 −5 lib/quix/ext/module.rb
View
@@ -2,18 +2,26 @@
class Module
#
# define_public_method
- # define_protectd_method
+ # define_protected_method
# define_private_method
# define_module_function
#
- [:public, :protected, :private, :module_function].each { |scope|
+
+ # TODO: jettison 1.8.6; remove eval and use |&block|
+ code = [
+ :public,
+ :protected,
+ :private,
+ :module_function
+ ].inject("") { |acc, scope|
name = scope == :module_function ? scope : "#{scope}_method"
- # TODO: jettison 1.8.6, remove eval and use |&block|
- eval <<-end_eval
+ # TODO: fix rcov %{} bug
+ acc << %^
def define_#{name}(name, &block)
define_method(name, &block)
#{scope}(name)
end
- end_eval
+ ^
}
+ eval(code)
end

0 comments on commit d0b4061

Please sign in to comment.