Last active
July 17, 2016 23:29
-
-
Save vcolavin/cde4d996b6d51d9b8747193ed6eec64c to your computer and use it in GitHub Desktop.
Example of ruby modules using classes to create truly private methods.
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 MyFirstModule | |
def first_public_method(my_string) | |
blah = PrivateMethods.new | |
return "#{my_string} #{blah.private_method}" | |
end | |
class PrivateMethods | |
def private_method | |
1 | |
end | |
end | |
end | |
module MySecondModule | |
def second_public_method(my_string) | |
blah = PrivateMethods.new | |
return "#{my_string} #{blah.private_method}" | |
end | |
class PrivateMethods | |
def 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