Skip to content

Instantly share code, notes, and snippets.

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