[Ironruby-core] RubyModule CreateAnonymousModule - NotImplementedException

Ben Hall ben2004uk at googlemail.com
Sun Sep 28 11:26:16 EDT 2008


Thanks Peter, I really appreciate it.

On Sun, Sep 28, 2008 at 3:55 PM, Peter Bacon Darwin
<bacondarwin at googlemail.com> wrote:
> And if you want the monkey patching to work then this should help...
>
> In RubyModule.cs you need:
>
>        // Ruby constructor:
>        public static RubyModule/*!*/
> CreateAnonymousModule([NotNull]BlockParam/*!*/ block, RubyClass/*!*/ self) {
>            RubyModule module =
> self.ExecutionContext.DefineModule(SymbolId.Empty);
>            object returnedValue =
> RubySites.ModuleEval(block.Proc.LocalScope, module, block.Proc);
>            if ( block.BlockJumped(returnedValue) ) {
>                return null;
>            }
>            return module;
>        }
>
> And in RubySites.cs you need:
>
>        private static readonly CallSite<Func<CallSite, CodeContext,
> RubyModule, Proc, object>> ModuleEvalSharedSite = CallSite<Func<CallSite,
> CodeContext, RubyModule, Proc, object>>.Create(
>            InstanceCallAction("module_eval",
> RubyCallSignature.WithBlock(0)));
>
>        public static object ModuleEval(CodeContext context, RubyModule
> self, Proc block) {
>            return ModuleEvalSharedSite.Target(ModuleEvalSharedSite,
> context, self, block);
>        }
>
> There are probably a number of corner cases that I have missed but this
> should work for the majority of uses.
>
> Regards,
> Pete
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>


More information about the Ironruby-core mailing list