Created
November 12, 2018 09:41
-
-
Save karuppasamy/a26547be3bd9efd91cbdcfbe59db1411 to your computer and use it in GitHub Desktop.
Ruby Module - Private, Public method
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 Bar | |
def self.included(base) | |
class << base | |
def public_method # public method | |
puts "public method" | |
end | |
def call_private # public method | |
puts "Call Private from Public" | |
private_method | |
end | |
private | |
def private_method | |
puts "Private method" | |
end | |
end | |
end | |
def module_method | |
puts "module method" | |
end | |
def call_module_private_method | |
puts "Call module private method from module inst" | |
module_private_method | |
end | |
private | |
def module_private_method | |
puts "module private method" | |
end | |
end | |
class Foo | |
include Bar | |
end | |
Foo.public_method | |
Foo.call_private | |
Foo.private_method # fail | |
Foo.new.module_method | |
Foo.new.call_module_private_method | |
Foo.new.module_private_method # fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment