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
class Class | |
def seal! | |
class_eval do | |
def self.method_added(method_name) | |
Object.const_set(name, @sealed) if defined?(@sealed) | |
end | |
def self.singleton_method_added(method_name) | |
Object.const_set(name, @sealed) if defined?(@sealed) | |
end | |
end | |
@sealed = self.clone | |
end | |
end | |
class Sealed | |
def foo | |
puts "denied" | |
end | |
def self.bar | |
puts "denied again" | |
end | |
seal! | |
end | |
class Sealed | |
def foo | |
puts "wuh-oh" | |
end | |
def self.bar | |
puts "double wuh-oh" | |
end | |
end | |
Sealed.new.foo | |
Sealed.bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment