凡在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. Scalaz Bind.bind在哪裏實現?
- 2. OutputStream實現在哪裏
- 3. Array.map的實現在哪裏?
- 4. System.ServiceModel.ServiceHost.Dispose()的實現在哪裏?
- 5. 檢測Mixin包含在哪裏
- 6. 在哪裏實現跨實體驗證?
- 7. JpaRepository接口實現,我想了解它的方法在哪裏實現?
- 8. 如何實現「在哪裏」在LINQ
- 9. 'hasSystemFeature()'方法的實現在哪裏?
- 10. 在哪裏實現的Global.asax方法
- 11. 在哪裏實現Swift協議?
- 12. 實現IHierarchyData時在哪裏指定URL
- 13. iTop,在哪裏實現onchange javascript?
- 14. 類擴展的實現在哪裏?
- 15. time.h實現代碼在哪裏?
- 16. IP Anycast Nameserver系統在哪裏實現?
- 17. 在哪裏實現BackgroundWorker。 Winforms c#
- 18. PowerShell 2.0 ICmdletProviderSupportsHelp是在哪裏實現的?
- 19. refreshToken端點實現在哪裏?
- 20. 堆棧函數的實現在哪裏?
- 21. Code-First MVC - AspNet表在哪裏實現?
- 22. ASP.NET MVC - 在哪裏實現映射器?
- 23. 在哪裏實現try catch塊?
- 24. java.sql.Connection接口的實現在哪裏?
- 25. C庫的實現在哪裏?
- 26. 我應該在哪裏實現Android onTouchListener?
- 27. sys/*。h文件的實現在哪裏?
- 28. @Future的實現在哪裏定義?
- 29. [modelname] _path-method在哪裏實現?
- 30. connect()和disconnect()在哪裏實現?
恐怕它被放置在vm/builtin/*中,並寫在cpp中。 –
你低估了Rubinius的冷靜:-) –