Created
October 3, 2012 15:15
-
-
Save dlikhten/3827497 to your computer and use it in GitHub Desktop.
Pub/Pri class methods in ruby
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 Herp | |
class << self | |
private | |
def foo | |
"foo" | |
end | |
public | |
def bar | |
"bar" | |
end | |
end | |
end | |
1.9.3p194 :062 > Herp.foo | |
NoMethodError: private method `foo' called for Herp:Class | |
from (irb):62 | |
from /Users/dlikhten/.rvm/gems/ruby-1.9.3-p194-perf@doorsteps/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start' | |
from /Users/dlikhten/.rvm/gems/ruby-1.9.3-p194-perf@doorsteps/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start' | |
from /Users/dlikhten/.rvm/gems/ruby-1.9.3-p194-perf@doorsteps/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>' | |
from script/rails:6:in `require' | |
from script/rails:6:in `<main>' | |
1.9.3p194 :063 > Herp.bar | |
=> "bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment