Created
February 8, 2019 23:37
-
-
Save saraid/5e5957b23c8d3b6f8626f3271d6d2a33 to your computer and use it in GitHub Desktop.
how to combine refinements
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
module Refinements | |
module DoFoo | |
refine Object do | |
def foo; :foo; end | |
end | |
end | |
module DoBar | |
refine Object do | |
def bar; :bar; end | |
end | |
end | |
module FooAndBar | |
include DoFoo | |
include DoBar | |
end | |
end | |
class A | |
using Refinements::FooAndBar | |
def self.test | |
[1.foo, 1.bar] | |
end | |
end | |
begin | |
A.test | |
puts "Success." | |
rescue NoMethodError | |
puts "Nope." | |
raise | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment