implement vs extend code example

Example: include vs extend

# Ruby program to understand include and extend
  
# Creating a module contains a method
module Geek
  def prints(x)
    puts x
  end
end
   
class GFG
  
  # by using both include and extend
  # we can access them by both instances
  #  and class name.
  include Geek
  extend Geek
end
  
# access the prints() in Geek
# module by include in Lord class
GFG.new.prints("Howdy") # object access
   
# access the prints() in Geek 
# module by extend it in Lord class
GFG.prints("GeeksforGeeks!!") # class access

Tags:

Misc Example