Adding methods to Kernel

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

You need to declare a “self” parameter, even though it will be unused.

From: [email protected]
[mailto:[email protected]] On Behalf Of Peter Bacon
Darwin
Sent: Sunday, July 13, 2008 1:46 PM
To: [email protected]
Subject: [Ironruby-core] Adding methods to Kernel

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

Magic thanks! I knew you needed this for Singleton methods but the fact
that
it was a private instance method as well threw me.

Now I can start hitting the rubyspec tests for BigDecimal.

Pete

From: [email protected]
[mailto:[email protected]] On Behalf Of Curt
Hagenlocher
Sent: Sunday,13 July 13, 2008 21:48
To: [email protected]
Subject: Re: [Ironruby-core] Adding methods to Kernel

You need to declare a “self” parameter, even though it will be unused.

From: [email protected]
[mailto:[email protected]] On Behalf Of Peter Bacon
Darwin
Sent: Sunday, July 13, 2008 1:46 PM
To: [email protected]
Subject: [Ironruby-core] Adding methods to Kernel

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