Last active
July 20, 2020 22:52
-
-
Save skatenerd/8970d4c66b815553397bb03703a7ece5 to your computer and use it in GitHub Desktop.
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 Base | |
A_VALUE = 2 | |
def foo | |
raise "NOT IMPLEMENTED" | |
end | |
end | |
class Sub < Base | |
def foo | |
return A_VALUE | |
end | |
end | |
class BadSub < Base | |
def foo | |
return A_VALUE + 1 | |
end | |
end | |
module Refiner | |
::Base.descendants.each do |descendant| | |
refine descendant do | |
def foo | |
p 'in refinement' | |
old_value = super | |
p "got #{old_value}" | |
if old_value % 2 != 0 | |
raise "NOT EVEN" | |
end | |
return old_value | |
end | |
end | |
end | |
end | |
using Refiner | |
Sub.new.foo | |
BadSub.new.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment