Skip to content

Instantly share code, notes, and snippets.

@onethirtyfive
Forked from skatenerd/refinement.rb
Created July 20, 2020 22:34
Show Gist options
  • Save onethirtyfive/135968f3c0dce2f782fcd0338d5194ae to your computer and use it in GitHub Desktop.
Save onethirtyfive/135968f3c0dce2f782fcd0338d5194ae to your computer and use it in GitHub Desktop.
class Base
A_VALUE = 2
def foo
end
end
module Refiner
refine Base do
def foo
old_value = super
if old_value % 2 != 0
raise "NOT EVEN"
end
end
end
end
class Sub < Base
def foo
super
return A_VALUE
end
end
class BadSub < Base
def foo
super
return A_VALUE + 1
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