Skip to content

Instantly share code, notes, and snippets.

@yangsu
Last active December 11, 2015 20:08
Show Gist options
  • Save yangsu/4652856 to your computer and use it in GitHub Desktop.
Save yangsu/4652856 to your computer and use it in GitHub Desktop.
Ruby Method Encapsulation
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