As far as I know you can’t use gems yet in IronRuby and that’s also why
there is no example with unit tests etc. It can’t be done atm.
IronRuby has a minispec framework built in but that isn’t as fully
featured
as rspec for example.
Basically building stuff with IronRuby is the same as with Ruby only now
you
can use everything from .NET too.
» ir -D
IronRuby 1.0.0.0 on .NET 2.0.50727.3053
Copyright (c) Microsoft Corporation. All rights reserved.
Note that local variables do not work today in the console.
As a workaround, use globals instead (eg $x = 42 instead of x = 42).
require ‘rubygems’
=> true
require ‘pathname2’
C:\tools\IronRuby\build\debug....\lib\ruby\site_ruby\1.8\rubygems/custom_require.rb:31:in
require': no such file oad -- pathname2 (LoadError) from c:\tools\IronRuby\src\microsoft.scripting.core\actions\matchcaller.generated.cs:35:in
Call3’
from
c:\tools\IronRuby\src\microsoft.scripting.core\actions\callsite.cs:275:in
UpdateAndExecute' from c:\tools\IronRuby\src\microsoft.scripting.core\actions\updatedelegates.generated.cs:45:in
Update3’
from :0
from
c:\tools\IronRuby\src\microsoft.scripting.core\actions\matchcaller.generated.cs:35:in
Call3' from c:\tools\IronRuby\src\microsoft.scripting.core\actions\callsite.cs:275:in
UpdateAndExecute’
from
c:\tools\IronRuby\src\microsoft.scripting.core\actions\updatedelegates.generated.cs:45:in
`Update3’
from :0
If you’re looking for the “Ruby way” of doing things then there are
plenty
of libraries and ruby projects that you can study, for me personally
there
is not much difference between programming against either. If you
already
know .NET it’s just a matter of getting the hang of Ruby like where and
when
to use metaprogramming, embracing hashes etc. For example:
class Member
attr_accessor :name, :age, :marital_status, :children
def initialize(options)
options.each do |key, value|
instance_variable_set “@#{key}”, value
end
end
end
member = Member.new :name => “Joe Schmoe”, :age => 27, :marital_status
=>
:married, :children => 2.1
puts member.name
Or you can take existing .NET classes and extend them
module StringExtensions
def to_uri
System::Uri.new self
end
end
require ‘mscorlib’
class System::String
include StringExtensions
end
or
System::String.include StringExtensions
Check out ironruby-contrib on github that should hold at least 2
projects
that go further than ‘hello world’.
http://github.com/ironruby/ironruby-contrib/
Cheers
Ivan