On Thu, 22 Dec 2005, David Heinemeier Hansson wrote:
i can look into this more but have some outstanding questions regarding the
purpose of redefining methods that way and the autoloading philosophy which
i'd like to understand before hacking.
The problem is definitely double inclusion. Rails is not double
inclusion safe and I don't think its worth making it so. So we should
instead make sure that it never happens.
unfortunately that means the fix must be rather inclusive....
here's a short summary of the problem extracted from the rails source base:
harp:~ > cat a.rb
module ActiveRecord
class Base
class << self
def instantiate
p 42
end
end
end
end
module ActiveRecord
module Callbacks
def self.append_features(base) #:nodoc:
super
base.extend(ClassMethods)
base.class_eval do
class << self
alias_method :instantiate_without_callbacks, :instantiate
alias_method :instantiate, :instantiate_with_callbacks
end
end
end
module ClassMethods
def instantiate_with_callbacks
instantiate_without_callbacks
end
end
end
end
ActiveRecord::Base.class_eval do
include ActiveRecord::Callbacks
include ActiveRecord::Callbacks
end
ActiveRecord::Base.instantiate
harp:~ > ruby a.rb
a.rb:25:in `instantiate_without_callbacks': stack level too deep
(SystemStackError)
from a.rb:25:in `instantiate'
from a.rb:37
the fix is quite simple
def __instantiate
p 42
end
alias_method :instantiate_without_callbacks, :__instantiate
alias_method :instantiate, :instantiate_with_callbacks
def instantiate_with_callbacks
instantiate_without_callbacks
end
but this kind of thing happens all over the place. of course it is only
triggered when double inclusion happens. i still do not understand why double
inclusion was occuring on some platforms and not others - but cleaning up this
fragile approach can only help matters. i'd volunteer but aren't familiar
enough with the code base to know all locations of this potential circular
method chaining...
the other approach is, of course, to implement a require_once functionality
early (first thing) in the rails code base. one i put together can be found
here.
http://wrath.rubyonrails.org/pipermail/rails-core/2005-December/000361.html
as this kind of fix might be able to be done at a global level with little
effort - it seems worth considering. obivously the above needs tested - i
haven't even run it on windows for intstance.
regards.
-a
--
===============================================================================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy. all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
===============================================================================
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core