Last active
December 27, 2017 23:34
-
-
Save onelharrison/8a12dbf9a91aa7ccf10497a709d4f56d to your computer and use it in GitHub Desktop.
Code snippet showing how to define private class methods in Ruby.
This file contains hidden or 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
class Toyota < Car | |
def self.name | |
self.i_am | |
end | |
private_class_method def self.i_am | |
"Toyota #{superclass}" | |
end | |
end | |
# => Toyota.name | |
# "Toyota Car" | |
# | |
# => Toyota.i_am # expecting an error | |
# private method `i_am' called for Toyota:Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment