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