凡在Rubinius的源是負責包括模塊的代碼?(具體放置模塊作爲超類對象類的。)Rubinius在哪裏實現了mixin?
3
A
回答
8
如果你看一下Module#include
的文檔,你會發現它代表Module#append_features
:
對每個參數以相反的順序調用
Module.append_features
。
爲Module#append_features
的文檔,依次介紹了(很簡單),默認的Ruby的mixin算法如何工作的:
當該模塊包含在另一個,Ruby調用此模塊中
append_features
,傳遞接收模塊mod
。 Ruby的默認實現是將此模塊的常量,方法和模塊變量添加到mod
,前提是此模塊尚未添加到mod
或其某個祖先。另見Module#include
。
如果您在Rubinius sourcecode看Module#append_features
,你會發現這是Module#include_into
別名:
# Called when this Module is being included in another Module. # This may be overridden for custom behaviour. The default # is to add constants, instance methods and module variables # of this Module and all Modules that this one includes to +klass+. # # See also #include. # alias_method :append_features, :include_into
所以,最後,Module#include_into
是實打實的:
# Add all constants, instance methods and module variables # of this Module and all Modules that this one includes to +klass+ # # This method is aliased as append_features as the default implementation # for that method. Kernel#extend calls this method directly through # Module#extend_object, because Kernel#extend should not use append_features. def include_into(klass) ...
您的具體問題:
中準確地放置模塊作爲超類對象類
在this loop回答的:
k = klass.direct_superclass while k if k.kind_of? Rubinius::IncludedModule # Oh, we found it. if k == mod # ok, if we're still within the directly included modules # of klass, then put future things after mod, not at the # beginning. insert_at = k unless superclass_seen add = false break end else superclass_seen = true end k = k.direct_superclass end
手錶insert_at
。
+0
偉大的anwser!謝謝! –
相關問題
- 1. System.ServiceModel.ServiceHost.Dispose()的實現在哪裏?
- 2. OutputStream實現在哪裏
- 3. Scalaz Bind.bind在哪裏實現?
- 4. 在哪裏實現跨實體驗證?
- 5. JpaRepository接口實現,我想了解它的方法在哪裏實現?
- 6. Code-First MVC - AspNet表在哪裏實現?
- 7. 我應該在哪裏實現Android onTouchListener?
- 8. ASP.NET MVC - 在哪裏實現映射器?
- 9. 在哪裏實現BackgroundWorker。 Winforms c#
- 10. PowerShell 2.0 ICmdletProviderSupportsHelp是在哪裏實現的?
- 11. 什麼時候/在哪裏實現FileSystemWatcher
- 12. 'hasSystemFeature()'方法的實現在哪裏?
- 13. @Future的實現在哪裏定義?
- 14. 實現IHierarchyData時在哪裏指定URL
- 15. 在哪裏實現try catch塊?
- 16. 我在哪裏實現我的功能?
- 17. refreshToken端點實現在哪裏?
- 18. java.sql.Connection接口的實現在哪裏?
- 19. 在哪裏實現Swift協議?
- 20. 堆棧函數的實現在哪裏?
- 21. PHP中的MD5實現 - 我哪裏錯了?
- 22. 哪裏錯了?
- 23. 如何在Flask中實現MIXIN?
- 24. 是否可以在C#中實現mixin?
- 25. debrelease在哪裏放了包?
- 26. Event.Keys在哪裏去了?
- 27. 在哪裏瞭解「位」?
- 28. set.iterator().......我在哪裏錯了?
- 29. Rubinius在RubySL
- 30. 從哪裏開始增強現實
恐怕它被放置在vm/builtin/*中,並寫在cpp中。 –
你低估了Rubinius的冷靜:-) –