An experimental Ruby native extension that allows changing an object's class at runtime.
gem install transfigure
require 'transfigure'
The transfigure gem adds the transfigure_into!
method onto Ruby's Object
class. Pass it another class to switch out the object's current class to another one:
class Foo
end
class Bar
end
obj = Foo.new
obj.is_a?(Foo) # => true
obj.transfigure_into!(Bar)
obj.is_a?(Foo) # => false
obj.is_a?(Bar) # => true
The code has only been tested on MRI (cruby) 3.1 and will definitely not work on other Ruby engines like JRuby or TruffleRuby.
bundle exec rspec
- Cameron C. Dutro: http://github.com/camertron