Skip to content

Instantly share code, notes, and snippets.

@timonv
Created April 9, 2013 13:03
Show Gist options
  • Save timonv/5345534 to your computer and use it in GitHub Desktop.
Save timonv/5345534 to your computer and use it in GitHub Desktop.
Private class methods in Ruby
class Person
def self.get_name
persons_name
end
def self.persons_name
"Sam"
end
private_class_method :persons_name
end
puts "Hey, " + Person.get_name # Works fine
puts "Hey, " + Person.persons_name # Raises
@timonv
Copy link
Author

timonv commented Apr 9, 2013

Or, you can define it in the eigenclass directly.

clas << self
  def persons_name
    "Sam"
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment