Hey everyone! I was wondering how the methods in Ruby that aren't called with the syntax ClassName.method_name
work. Some off the top of my head are puts
, print
, gets
, chomp
. These methods can be called without using the dot operator. Why is this? Where do they come from? And how can I see the full list of such methods?
All methods in Kernel
will be available to all objects of class Object
or any class derived from Object
. You can use Kernel.instance_methods
to list them.
They come from the Kernel
module that is automatically included for each class. Those
irb(main):001:0> class Foo
irb(main):002:1> end
=> nil
irb(main):003:0> Foo.included_modules
=> [Kernel]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With