Skip to content

Instantly share code, notes, and snippets.

@asaaki
Created November 1, 2017 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaaki/c697054f625233cafa61483ab1db1fc8 to your computer and use it in GitHub Desktop.
Save asaaki/c697054f625233cafa61483ab1db1fc8 to your computer and use it in GitHub Desktop.
[Ruby] Private constants check
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