Skip to content

Instantly share code, notes, and snippets.

@karuppasamy
Created November 12, 2018 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karuppasamy/a26547be3bd9efd91cbdcfbe59db1411 to your computer and use it in GitHub Desktop.
Save karuppasamy/a26547be3bd9efd91cbdcfbe59db1411 to your computer and use it in GitHub Desktop.
Ruby Module - Private, Public method
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