[Ironruby-core] Adding methods to Kernel

Peter Bacon Darwin bacondarwin at googlemail.com
Sun Jul 13 16:45:32 EDT 2008


I am still having problems adding the BigDecimal method into the Kernel
module.  As I understand it the correct method is to create a new class that
extends Kernel and adds the methods as both Private-Instance and
Public-Singleton.  This is the code:

 

namespace Ruby.StandardLibrary.BigDecimal {

    [RubyModule(Extends = typeof(Kernel))]

    public static class KernelOps {

        [RubyMethod("BigDecimal", RubyMethodAttributes.PrivateInstance)]

        [RubyMethod("BigDecimal", RubyMethodAttributes.PublicSingleton)]

        public static BigDecimal/*!*/ CreateBigDecimal(CodeContext/*!*/
context, [NotNull]MutableString/*!*/ value, [Optional]int n) {

            return BigDecimalOps.CreateBigDecimal(value, n);

        }

        [RubyMethod("BigDecimal", RubyMethodAttributes.PrivateInstance)]

        [RubyMethod("BigDecimal", RubyMethodAttributes.PublicSingleton)]

        public static BigDecimal/*!*/ CreateBigDecimal(CodeContext/*!*/
context, object value, [Optional]int n) {

            return BigDecimalOps.CreateBigDecimal(context, value, n);

        }

    }

}

 

This appears to create the methods (you can see them in Kernel.methods)  but
it is not possible to call them.  You always get an ArgumentError thrown
with "incorrect type or number of parameters" as a message.

 

I have been digging through the code but I can't work out why this is
happening.  One thing that seems a little worrying but not necessarily wrong
is that it appears that the target (self) has a RubyClass of type
Ruby.Builtins. BuiltinsLibraryInitializer, which seems rather bizarre.

 

Currently I am able to get around this by defining the methods in Ruby
itself, I changed the bigdecimal.rb file in the libs folder to:

 

load_assembly 'IronRuby.Libraries', 'Ruby.StandardLibrary.BigDecimal'

class Object

                def BigDecimal(v, n = 0)

                                BigDecimal.new(v,n)

                end

end

 

Any ideas?

Pete

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20080713/30c99dc2/attachment-0001.html>


More information about the Ironruby-core mailing list