Created
November 1, 2017 12:50
-
-
Save asaaki/c697054f625233cafa61483ab1db1fc8 to your computer and use it in GitHub Desktop.
[Ruby] Private constants check
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
require 'active_support' | |
module MyConcern | |
extend ActiveSupport::Concern | |
class PrivateClass | |
def self.pcall | |
:pcall_result | |
end | |
end | |
private_constant :PrivateClass | |
def some_call | |
PrivateClass.pcall | |
end | |
end | |
class MyClass | |
include MyConcern | |
end | |
MyClass.new.some_call | |
#=> :pcall_result | |
MyClass::PrivateClass | |
#=> NameError: private constant #<MyConcern:0x007fd6e3d5cbd8>::PrivateClass referenced |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment