Created
May 23, 2014 23:49
-
-
Save anonymous/dfbf0572175f07e01e13 to your computer and use it in GitHub Desktop.
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 Barkable | |
def bark! | |
puts "Bark! I'm #{state}!!" | |
end | |
def state | |
["happy", "sad", "melancholy"][rand(3)] | |
end | |
end | |
class Dog | |
include Barkable | |
def initialize | |
bark! | |
# I don't want/need Barkable::state() to be available from this point. | |
# I might want to use that method name for something more appropriate | |
# to the "Dog" class, and I don't want to deal with collisions. | |
# What's best practice for methods I only need to access from within | |
# a module? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment