my question is probably a little bit stupid, but anyway it would be nice if
somebody could give me an answer:
As everybody knows, the method puts is reachable from anywhere even from
own classes without requiring anything.
How can I make my own method reachable from anywhere? Where do I have to
put them?
my question is probably a little bit stupid, but anyway it would be nice
if
somebody could give me an answer:
As everybody knows, the method puts is reachable from anywhere even from
own classes without requiring anything.
How can I make my own method reachable from anywhere? Where do I have to
put them?
simply put your method in the “Kernel” module:
module Kernel
def test
puts “reachable from anywhere!”
end
end
the reason is that the module Kernel is included by the Object class.
As everybody knows, the method puts is reachable from anywhere even from
own classes without requiring anything.
How can I make my own method reachable from anywhere? Where do I have to
put them?
simply put your method in the “Kernel” module:
module Kernel
def test
puts “reachable from anywhere!”
end
end
the reason is that the module Kernel is included by the Object class.
my question is probably a little bit stupid, but anyway it would be nice
if
somebody could give me an answer:
As everybody knows, the method puts is reachable from anywhere even from
own classes without requiring anything.
How can I make my own method reachable from anywhere? Where do I have to
put them?
simply put your method in the “Kernel” module:
module Kernel
def test
puts “reachable from anywhere!”
end
end
the reason is that the module Kernel is included by the Object class.
This works really fine with the normal ruby interpreter but unfortunately
not with mod_ruby…
I tried already to put it in ‘Apache’…
Any suggestions?
This works really fine with the normal ruby interpreter but unfortunately
not with mod_ruby…
···
----- Original Message -----
From: “Dominik Werder” dwerder@gmx.net
the reason is that the module Kernel is included by the Object class.
Because you main script in mod_ruby is wrapped in an invisible module, when
you add a method to Kernel, you are really adding it to <your hidden
::Kernel. If you put your code into another file and have your
mod_ruby script require' or load’ it (either should work), then it gets
loaded into the top level, and this should work fine.
The problem is that the syntax for creating and extending a module or class
are the same, just like the syntax for creating or assigning to a variable
are the same. (Kind of neat, but ultimately it’s one of the only things I
don’t like about Ruby.) To extend a builtin module or class in your primary
mod_ruby script, try code which only works for existing modules and
classes, such as: