I'm going through the Facets API and picking some methods to include in my refinement-compatible patch library.
I've hit a snag trying to patch Kernel. It's a module, whereas the other stuff I've patched has been classes (String, Array, etc.)
Here's proof that can't can't be refined using my standard approach for core classes:
module Patch
refine Kernel do
def patched?
true
end
end
end
# TypeError: wrong argument type Module (expected Class)
# from (pry):16:in `refine'
I've also tried wrapping the Kernel module in a class, and changing the global reference to Kernel to that class.
class MyKernel
include Kernel
extend Kernel
end
# not sure if Object::Kernel is really the global reference
Object::Kernel = MyKernel
module Patch
refine MyKernel do
def patched?
true
end
end
end
class Test
using Patch
patched?
end
# NoMethodError: undefined method `patched?' for Test:Class
# from (pry):15:in `<class:Test>'
In this case I could successfully get the same functionality by replacing Kernel with Object:
module Patch
refine Object do
def patched?
true
end
end
end
class Test
using Patch
patched?
end
But I'm not sure if I could get this equivalency with other core modules such as Enumerable.