rubylibgosu

What does include means in gosu


To use gosu in ruby program, we have to called out gosu.

require "gosu"

But what does include means in a gosu program.

require "gosu"
include Gosu

what is the purpose of include Gosu in the program and what does it do.


Solution

  • Including a module in a given context makes the methods defined in that module available in that context.

    In this case, you're making the methods defined the Gosu module available in the current context.

    See Module#include.

    For example, including Test causes foo to be added to the current context, so that foo can be invoked:

    module Test
      def foo
        "bar"
      end
    end
    
    include Test
    
    foo # "bar"