Skip to content

Instantly share code, notes, and snippets.

@JuzerShakir
Last active July 8, 2021 18:24
Show Gist options
  • Save JuzerShakir/f69dc3f7b238d6c9957ea8325040687f to your computer and use it in GitHub Desktop.
Save JuzerShakir/f69dc3f7b238d6c9957ea8325040687f to your computer and use it in GitHub Desktop.
Used in medium
module Test
def self.hellow
puts "I'm a module method."
end
def hello
puts "I'm an instance method."
end
end
# => call required file without extension .rb
require_relative '01.define_module'
# call methods 1st way
extend Test
# access module method
Test::hellow # => I'm a module method.
hellow # => undefined local variable or method `hellow' for main:Object (NameError)
# access instance method
Test::hello # => undefined method `hello' for Test:Module (NoMethodError)
hello # => I'm an instance method.
# ---------------------------------------------------------------------------- #
# call methods 2nd way
include Test
# access module method
Test::hellow # => I'm a module method.
hellow # => undefined local variable or method `hellow' for main:Object (NameError)
# access instance method
Test::hello # => I'm an instance method.
hello # => I'm an instance method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment