# Adding methods to Kernel

**URL:** <https://www.ruby-forum.com/t/adding-methods-to-kernel/142956>\
**Category:** IronRuby\
**Created:** [July 13, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/adding-methods-to-kernel/142956 "2008-07-13T22:46:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [July 13, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/adding-methods-to-kernel/142956/1 "2008-07-13T22:46:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [July 13, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/adding-methods-to-kernel/142956/2 "2008-07-13T22:52:28Z")

</div>

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

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Peter Bacon  
Darwin  
Sent: Sunday, July 13, 2008 1:46 PM  
To: removed\_email\_address@domain.invalid  
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

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [July 13, 2008, 11:16pm UTC](https://www.ruby-forum.com/t/adding-methods-to-kernel/142956/3 "2008-07-13T23:16:27Z")

</div>

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: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Curt  
Hagenlocher  
Sent: Sunday,13 July 13, 2008 21:48  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Adding methods to Kernel

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

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Peter Bacon  
Darwin  
Sent: Sunday, July 13, 2008 1:46 PM  
To: removed\_email\_address@domain.invalid  
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
