Created
December 18, 2014 09:12
-
-
Save Integralist/bb8760d11a03c88da151 to your computer and use it in GitHub Desktop.
Ruby: private class level methods
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 Foo | |
class << self | |
def bar | |
p "im public" | |
end | |
private | |
def baz | |
p "im private" | |
end | |
end | |
end | |
Foo.bar # => im public | |
Foo.baz # => NoMethodError: private method `baz' called for Foo:Class |
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 Foo | |
def self.bar | |
p "im public" | |
end | |
private | |
def self.baz | |
p "im private" | |
end | |
end | |
Foo.bar # => im public | |
Foo.baz # => im private |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also https://stackoverflow.com/a/12925407/322020 and other answers there.