Hello
I want to make my changes inside a module (all "required" files are inside that module XY)
because these changes should only work if the module is included.
Is there a way to change the Namespace to a specific path (like Root::ModuleA::ClassB, or UP::... relative like in dirs)?
However, it's probably not a good idea to monkey-patch
the Array class globally.
I would strongly recommend you look up Ruby's refinements.
Regards,
Marcus
···
Am 15.01.2017 um 18:55 schrieb Die Optimisten:
I want to make my changes inside a module (all "required" files are
inside that module XY)
because these changes should only work if the module is included.
Is there a way to change the Namespace to a specific path (like
Root::ModuleA::ClassB, or UP::... relative like in dirs)?
Thank you!
But: (how?) is it done (on class Array), so that only code that includes A (or inside the module definition) is affected? - Outside the module it should only work using [1,2].A::myjoin (the syntax is very wrong?)
What is the class for print, puts, etc ?
module X
def self.p_NL(v)
: v,"\n"
end
end
X::p_NL(1)
How can I see from which class is a specific method?
def show_class_of_method(:meth)
???
end
Opti
···
On 2017-01-15 19:16, sto.mar@web.de wrote:
Am 15.01.2017 um 18:55 schrieb Die Optimisten:
I want to make my changes inside a module (all "required" files are
inside that module XY)
because these changes should only work if the module is included.
Is there a way to change the Namespace to a specific path (like
Root::ModuleA::ClassB, or UP::... relative like in dirs)?
module A
class Array
def myjoin
...
end
end
[1,2,3].myjoin # not found
end
# Outside the module:
[1,2,3].myjoin # not found
Whats the namespace for core?
## like Main::Array
::Array
However, it's probably not a good idea to monkey-patch
the Array class globally.
I would strongly recommend you look up Ruby's refinements.