Last active
June 14, 2017 18:54
-
-
Save pushcx/3c30be556b393b5fb58a4845459e3e77 to your computer and use it in GitHub Desktop.
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 'binding_of_caller' | |
# https://twitter.com/garybernhardt/status/875037876215357440 | |
class ReallyParticularInsantiation | |
def initialize | |
b = binding.of_caller(1) | |
# could also b.eval to get at __FILE__ and __LINENO__ | |
if b.eval('self.class') != Foo or b.eval('__method__') != :try | |
raise RuntimeError, "I don't even know what to call this coupling" | |
end | |
puts 'ReallyParticularInsantiation#initalize allowed' | |
end | |
end | |
class Foo | |
def try | |
ReallyParticularInsantiation.new | |
end | |
end | |
class Bar | |
def try | |
ReallyParticularInsantiation.new | |
end | |
end | |
def kernel_method_try | |
ReallyParticularInsantiation.new | |
end | |
Foo.new.try | |
Bar.new.try | |
kernel_method_try | |
ReallyParticularInsantiation.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment