Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Created December 27, 2017 23:20
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 onelharrison/bc60cf4f0cfb6424bb09186c1a3874ca to your computer and use it in GitHub Desktop.
Save onelharrison/bc60cf4f0cfb6424bb09186c1a3874ca to your computer and use it in GitHub Desktop.
Code snippet showing how to define private class methods in Ruby.
class Toyota < Car
class << self
def name
i_am
end
private
def i_am
"Toyota #{superclass}"
end
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