warning: defining StrongSpecFixture.allocate is deprecated; use
rb_define_alloc_func()
Is there a way to redefine allocate in Ruby in a way that works across
all of the different Ruby implementations (JRuby, Rubinius, etc)?
Not really. Most impls, including MRI and JRuby, don’t actually
dispatch to allocate when constructing a new object, so there’s no way
to replace it at runtime. This is done partially for performance
reasons, and partially (at least in JRuby’s case) because allocate
initializes impossible-to-initialize-any-other-way internal state for
the object, so replacing it would be a bad thing.
JRuby 1.6 does provide a solid start on a compatible C API, though, so
if it’s native-level allocate binding you need, that’s an option. And
of course there’s impl-specific ways to do this entirely from Ruby
code in JRuby and probably others.
Charlie
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.