Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example using modules within modules to create private namespaces
module MyFirstModule
def first_public_method(my_string)
return "#{my_string} #{PrivateMethods.private_method}"
end
module PrivateMethods
def self.private_method
1
end
end
end
module MySecondModule
def second_public_method(my_string)
return "#{my_string} #{PrivateMethods.private_method}"
end
module PrivateMethods
def self.private_method
2
end
end
end
class MyClass
include MyFirstModule
include MySecondModule
end
puts MyClass.new.first_public_method("hey") # => "hey 1"
puts MyClass.new.second_public_method("hey") # => "hey 2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment