Last active
December 11, 2015 20:08
-
-
Save yangsu/4652856 to your computer and use it in GitHub Desktop.
Ruby Method Encapsulation
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
class MyClass | |
def self.class_method # creates a class method. Always public | |
"class_method" | |
end | |
def method1 # default is 'public' | |
"method1" | |
end | |
protected # subsequent methods will be 'protected' | |
def method2 # will be 'protected' | |
"method2" | |
end | |
private # subsequent methods will be 'private' | |
def method3 # will be 'private' | |
"method3" | |
end | |
public # subsequent methods will be 'public' | |
def method4 # and this will be 'public' | |
"method4" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment