Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Last active July 20, 2020 22:52
Show Gist options
  • Save skatenerd/8970d4c66b815553397bb03703a7ece5 to your computer and use it in GitHub Desktop.
Save skatenerd/8970d4c66b815553397bb03703a7ece5 to your computer and use it in GitHub Desktop.
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