[Ironruby-core] How to extend builtin classes?

Curt Hagenlocher curt at hagenlocher.org
Sun Oct 7 12:24:23 EDT 2007


On 10/6/07, Krishna Krishnamaneni <kitti.k at gmail.com> wrote:
>
>
> How do we extend inbuilt classes. For example Float doesn't have *
> method implemented. I tried adding this method:


It's not sufficient to add the method to the class definition.  You also
have to force the method information to be initialized by updating the file
Initializer.Generated.cs.  As its name suggests, this file is automatically
generated from the source code by running the "ClassInitGenerator" program
-- a batch file that does this is at Builtins\GenerateInitializers.cmd.

Unfortunately, the version of the source that's checked into RubyForge has a
bunch of broken paths for this purpose -- at least when not using Visual
Studio.  I tried to use msbuild directly to build ClassInitGenerator.exe,
and found that I had to make the following edits for things to work
correctly:

utils\ironruby.classinitgenerator\ClassInitGenerator.csproj
  add reference to ..\..\build\debug\Microsoft.Scripting.dll
  add reference to ..\..\build\debug\Ruby.dll
  fix the reference path for Microsoft.Scripting.csproj
  fix the reference path for Ruby.csproj
src\ironruby\Ruby.csproj
  fix the reference path for Microsoft.Scripting.csproj
src\ironruby\Builtins\GenerateInitializers.cmd
  fix the path to ClassInitGenerator.exe

After making these changes, I ran GenerateInitializers.cmd and rebuilt
IronRuby using the Rakefile.  Your change then worked:

F:\IronRuby>build\release\rbx.exe
IronRuby Pre-Alpha (1.0.0.0) on .NET 2.0.50727.312
Copyright (c) Microsoft Corporation. All rights reserved.
>>> 1.2 + 1.2
=> 2.4
>>> 1.2 * 1.2
=> 1.44

--
Curt Hagenlocher
curt at hagenlocher.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071007/4c5863e0/attachment.html 


More information about the Ironruby-core mailing list