Created
September 30, 2013 23:08
-
-
Save stewart/6771611 to your computer and use it in GitHub Desktop.
Weird scope bug?
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 WorkingClass | |
def call | |
hidden_method | |
end | |
private | |
def self.hidden_method | |
"Found me!" | |
end | |
def hidden_method | |
self.class.hidden_method | |
end | |
end | |
class FailingClass | |
def call | |
hidden_method | |
end | |
class << self | |
private | |
def hidden_method | |
"Found me!" | |
end | |
end | |
private | |
def hidden_method | |
self.class.hidden_method | |
end | |
end | |
WorkingClass.new.call | |
#=> "Found me!" | |
FailingClass.new.call | |
#=> private method `hidden_method' called for FailingClass:Class (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment