For some reason, I want to use classes / modules with a namespace, since they are in the global namespace in the IRB.
For example, I have a module MyCoreand a class MyUserinside it. Is there any mechanism or hook for IRB to enable MyCore::MyUserin such a way that I can only name it MyUser.newwithout prefixing it with MyCore?
MyCore
MyUser
MyCore::MyUser
MyUser.new
You can just do
include MyCore myUser = MyUser.new
Using it includeadds all the constants in the module to your current class.
include
class WhereIWantToIncludeMyCore include MyCore def initialize user = MyUser.new end end
, class, Object.
class
Object
-
MU = MyCore::MyUser
, .
You can always do
MyUser = MyCore::MyUser
If you want to get all included modules / classes:
MyCore.constants.each do |const| Object.const_set(const, MyCore.const_get(const)) end
i research this problem and i found this talking and scripts
but I thought this gem is wrap_in_moduledoing best practice
wrap_in_module
hope this helps.
Source: https://habr.com/ru/post/1539586/More articles:USB descriptor - embeddedHow to use groups in NoFlo? - noflo@Autowired at @Service? - javaHow to change HTML properties as I duplicate it in jQuery? - jqueryDatagridview how to discard a selected row in a custom object - c #cURL extract encoded HTML from Pirate Bay - phpПроблема с объединением нескольких файлов JSON в Python - jsonMahapps.Metro changes the theme of unified management - wpfJava: расшифровка цезарного шифра с неизвестными позициями - javaAngularJS $ Location Preventing the Browser from Using the Following Hyperlinks - angularjsAll Articles