Skip to content

Instantly share code, notes, and snippets.

@vcolavin
Last active July 17, 2016 23:29
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 vcolavin/127dd425a99b6ebca7c4d1e44bd08226 to your computer and use it in GitHub Desktop.
Save vcolavin/127dd425a99b6ebca7c4d1e44bd08226 to your computer and use it in GitHub Desktop.
Example of private module methods overwriting each other when mixed in
module MyFirstModule
def first_public_method(my_string)
return "#{my_string} #{private_method}"
end
private
def private_method
1
end
end
module MySecondModule
def second_public_method(my_string)
return "#{my_string} #{private_method}"
end
private
def private_method
2
end
end
class MyClass
include MyFirstModule
include MySecondModule
end
puts MyClass.new.first_public_method("hey") # => "hey 2"
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