- Posted by Shay Friedman on March 28, 2009
In the latest version of IronRuby (0.3), the ability to use Generic .Net classes was added. I couldn’t find anywhere how to do that so I dug it out of the code and now I’ll share it with you!
Example #1 - List
This is how to define an Int32 list, add two numbers to it and print them:
|
list = System::Collections::Generic::List[System::Int32].new
list.add 4 list.add 12
list.each { |x| puts x }
|
Of course we can also use Ruby type like Numeric, String, etc.
Example #2 – Dictionary
This is how to declare a number-string dictionary, add values to it and print them:
|
dict = System::Collections::Generic::Dictionary[Fixnum, String].new dict.add 1, "Hey" dict.add 15, "There"
dict.each { |x| puts "#{x.key} - #{x.value}" }
|
All the best,
Shay.
- Posted by Shay Friedman on March 21, 2009
Great news! As Jimmy Schementi describes it – the “conference-driven development schedule” of IronRuby brings us some news for the MIX09 conference. It’s the 0.3 version of IronRuby!
So what’s new in 0.3?
- IronRuby now passes 10% more of the RubySpec than v0.2 has. Make sure to check IronRuby.info in order to get up-to-date statistics.
- Better .Net interoperability – you can now call generic methods and implement interfaces!
- More! you can read about all changes in the CHANGELOG.txt file that you’ll find in the zip.
Grab it: http://rubyforge.org/frs/download.php/53552/ironruby-0.3.0.zip
Enjoy,
Shay.