J
Jason Creighton
Hi,
How are global methods defined in Ruby? I know you can just
def just_a_method(arg)
puts "do stuff"
end
....and you can call it anywhere. I had thought that those methods are
automagically added to Kernel, but appearently that's only methods
defined from C with rb_define_global_function (which just adds the
method to Kernel), or those methods define in Kernel like so
class << Kernel
def just_a_method(arg)
puts "do stuff"
end
end
or:
module Kernel
def Kernel.just_a_method(arg)
puts "do stuff"
end
end
But anyway, the question is, what happens to methods defined at the
top-level like that? Are they just added to Object? And if that's the
case, why do we even have Kernel?
Jason Creighton
How are global methods defined in Ruby? I know you can just
def just_a_method(arg)
puts "do stuff"
end
....and you can call it anywhere. I had thought that those methods are
automagically added to Kernel, but appearently that's only methods
defined from C with rb_define_global_function (which just adds the
method to Kernel), or those methods define in Kernel like so
class << Kernel
def just_a_method(arg)
puts "do stuff"
end
end
or:
module Kernel
def Kernel.just_a_method(arg)
puts "do stuff"
end
end
But anyway, the question is, what happens to methods defined at the
top-level like that? Are they just added to Object? And if that's the
case, why do we even have Kernel?
Jason Creighton