module Ext
refine Hash do
def foo
puts :in_foo
end
def bar
puts :in_bar
foo
end
end
end
module Test
using Ext
Hash.new.bar
end
# in_bar
# in_foo
# => nil
This works as expected. But if I want to share foo
and bar
between Hash
and Array
by using include
, it fails.
module Shared
def foo
puts :in_foo
end
def bar
puts :in_bar
foo
end
end
module Ext
refine Hash do
include Shared
end
refine Array do
include Shared
end
end
module Test
using Ext
Hash.new.bar
end
# in_bar
# NameError: undefined local variable or method `foo' for {}:Hash
Is there any way to share code between refinements?