Last active
December 11, 2015 20:08
-
-
Save yangsu/4652861 to your computer and use it in GitHub Desktop.
Ruby Method Encapsulation Alternative
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 | |
# define method 1 through 4 without and encapulation directives ... | |
public :method1, :method4 | |
protected :method2 | |
private :method3 | |
end | |
a = MyClass.new | |
puts MyClass.class_method # => class_method | |
puts a.method1 # => method1 | |
puts a.method2 # => protected method `method2' called for ... (NoMethodError) | |
puts a.method3 # => private method `method3' called for ... (NoMethodError) | |
puts a.method4 # => method4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment