Skip to content
Browse files

Remove leak in development mode

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4611 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2482e17 commit 378a93543092c95331beac53af56c476284564aa @seckar seckar committed Jul 17, 2006
Showing with 27 additions and 21 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +25 −21 actionpack/lib/action_controller/routing.rb
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Remove leak in development mode by replacing define_method with module_eval. [Nicholas Seckar]
+
* Provide support for decimal columns to form helpers. Closes #5672. [dave@pragprog.com]
* Update documentation for erb trim syntax. #5651 [matt@mattmargolis.net]
View
46 actionpack/lib/action_controller/routing.rb
@@ -858,9 +858,11 @@ def define_named_route_methods(name, route)
def define_hash_access(route, name, kind, options)
selector = hash_access_name(name, kind)
- @module.send(:define_method, selector) do |*args|
- args.first ? options.merge(args.first) : options
- end
+ @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks
+ def #{selector}(options = nil)
+ options ? #{options.inspect}.merge(options) : #{options.inspect}
+ end
+ end_eval
@module.send(:protected, selector)
helpers << selector
end
@@ -874,26 +876,28 @@ def define_url_helper(route, name, kind, options)
end.compact
hash_access_method = hash_access_name(name, kind)
- @module.send(:define_method, selector) do |*args|
- opts = if args.empty? || Hash === args.first
- args.first || {}
- else
- # allow ordered parameters to be associated with corresponding
- # dynamic segments, so you can do
- #
- # foo_url(bar, baz, bang)
- #
- # instead of
- #
- # foo_url(:bar => bar, :baz => baz, :bang => bang)
- args.zip(segment_keys).inject({}) do |h, (v, k)|
- h[k] = v
- h
+ @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks
+ def #{selector}(*args)
+ opts = if args.empty? || Hash === args.first
+ args.first || {}
+ else
+ # allow ordered parameters to be associated with corresponding
+ # dynamic segments, so you can do
+ #
+ # foo_url(bar, baz, bang)
+ #
+ # instead of
+ #
+ # foo_url(:bar => bar, :baz => baz, :bang => bang)
+ args.zip(#{segment_keys.inspect}).inject({}) do |h, (v, k)|
+ h[k] = v
+ h
+ end
end
+
+ url_for(#{hash_access_method}(opts))
end
-
- url_for(send(hash_access_method, opts))
- end
+ end_eval
@module.send(:protected, selector)
helpers << selector
end

0 comments on commit 378a935

Please sign in to comment.
Something went wrong with that request. Please try again.