Last active
July 8, 2021 18:24
-
-
Save JuzerShakir/f69dc3f7b238d6c9957ea8325040687f to your computer and use it in GitHub Desktop.
Used in medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test | |
def self.hellow | |
puts "I'm a module method." | |
end | |
def hello | |
puts "I'm an instance method." | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# => 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