SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

October 2009 - Posts

  • IronRuby Integration in SharpDevelop 3.1

    Support for IronRuby 0.9.1 is now available for SharpDevelop 3.1. The IronRuby addin is an early alpha preview release/proof of concept and is not an official part of SharpDevelop 3.1 so it is available as a separate download at the end of this post.

    Features

    • Code folding
    • Syntax highlighting
    • File and project templates for Console and Windows Forms applications
    • IronRuby Console window
    • Windows Forms designer (limited)
    • C# and VB.NET code conversion to Ruby (limited)

    Please note that the forms designer and code conversion need a lot more work.

    Creating a Windows Application

    Open up the new project dialog by selecting New then Solution from the File menu. Selecting the Ruby category will show two project templates. One will create a Windows console application and the other will create a Windows Forms application.

    New IronRuby Project Dialog

    To run your application ensure the Program.rb file is in the active text editor window then select Run from the Ruby menu. This will run your code with the IronRuby console (ir.exe). Alternatively you can run the application by selecting Run from the Debug menu but you will first need to configure the project options. Select Project Options from the Project menu to open up the Debug project options.

    Debug project options dialog

    You will need to add ${ProjectDir} to the command line arguments and working directory as shown above. The -19 command line argument is used to enable Ruby 1.9 support otherwise the IronRuby console will not be able to load any UTF-8 source code files.

    Currently you cannot debug your code even if the -D command line argument is specified.

    If you are running a windows app and nothing seems to happen then open a command line window and run it from there. This way you should see any errors reported from the IronRuby console.

    Designing Windows Forms

    The Windows Forms designer is still in its early stages so please be warned that it may break the form's code or worse. The designer code generation is a lot more complete than the designer loader so the designer will most likely fail to load all controls into the designer.

    The designer can be opened in the usual way by opening the form in the text editor and selecting the Design tab at the bottom of the text editor. Once open in the designer you can add controls to the form in the usual way from the Tools window. In the screenshot below a label, text box and a button have been added.

    Main form designed in designer

    Click the Source tab to view the generated code in the InitializeComponents method. Make sure you do this before trying to save the code.

    Generated form code

    IronRuby Console

    To open the IronRuby Console window select Tools, Ruby Console from the View menu.

    View IronRuby Console menu item

    When you type Ruby code into the IronRuby Console you will get code completion when you press the '.' character.

    IronRuby Console code completion

    Code Folding

    Code folding allows you to collapse regions of a class.

    Folded ruby code

    Code Conversion

    To convert VB.NET or C# to Ruby open the file you want to convert and then select Convert code to Ruby from the Tools menu.

    Convert code to Ruby menu item

    The code conversion is limited to classes so it will not convert an arbitary piece of code that is not inside a class. A C# class being converted to Ruby is shown below.

    C# code before converting to Ruby

    Converted Ruby code

    The code conversion is still at an early stage of development so it will fail on complicated classes.

    Class View

    Classes in the open solution will be displayed in the Class browser (Select Classes from the View menu).

    Ruby class in Classes window

    From there you can double click a class or method and the text editor will display the corresponding code.

    Installing the IronRuby AddIn

    1. Rename the IronRubyAddIn-0.1.zip file to IronRubyAddIn-0.1.sdaddin.
    2. From the Tools menu select AddIn Manager .

      Tools AddIn Manager menu item

    3. Click the Install AddIn button.

      AddIn Manager dialog

    4. In the Open File Dialog browse to the IronRubyAddIn-0.1.sdaddin file and click the Open button.

      AddIn installed confirmation dialog.

    5. Click the Close button.
    6. Restart SharpDevelop.

    Ruby Links

    Some of the Ruby tutorials and links used whilst creating the IronRuby addin.

    1. Ruby documentation.
    2. Book of Ruby by Huw Collingbourne.
    3. IronRuby homepage.

    Downloads

    IronRubyAddIn0.1.zip

    IronRubyAddIn0.1-src.zip

    Posted Oct 04 2009, 01:32 PM by MattWard with no comments
    Filed under: ,
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.