# Looking for Examples

**URL:** <https://www.ruby-forum.com/t/looking-for-examples/146964>\
**Category:** IronRuby\
**Created:** [August 27, 2008, 3:45am UTC](https://www.ruby-forum.com/t/looking-for-examples/146964 "2008-08-27T03:45:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 3:45am UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/1 "2008-08-27T03:45:05Z")

</div>

I’m wondering if anyone can point me to some good example projects  
using IronRuby. Specifically I’m looking for libraries and projects  
using some of the things we take for granted with regular ruby  
development - rake, gems, rspec, etc. I’m starting a project of my  
own and since there isn’t a lot of documentation out there yet I  
figure looking at other projects is the best way to see how it’s done.

I’m not looking for projects that just use small pieces of IronRuby -  
I really want to see how someone would build a library or end-to-end  
solution leveraging gems, rake tasks, and unit testing in IronRuby.

Thanks!

Glen Cooper  
(425) 802-6627  
[www.glenc.net](http://www.glenc.net)

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 9:44am UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/2 "2008-08-27T09:44:15Z")

</div>

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/](http://github.com/ironruby/ironruby-contrib/)

Cheers  
Ivan

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 5:11pm UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/3 "2008-08-27T17:11:52Z")

</div>

The thing with gems is that it’s going to be quite tricky… some of the  
very  
useful ones (hpricot for example) depend on C-extensions and then they  
need  
to be ported first to .NET.

At this moment i would try to include them in a lib folder or something  
and  
then require them when I load my script. (read what merb does ;))  
because  
manually installing doesn’t work yet either at least not when I tried  
that  
this morning. At this moment i wouldn’t use IronRuby for anything that  
has  
to go into production, that being said there most of the time there are  
alternatives in the .NET world and you can just leverage those.

Out of curiosity which libraries did you want to use?

Cheers  
Ivan

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/4 "2008-08-27T16:56:01Z")

</div>

Thanks for the response. So let me ask you this. If you were to  
start building a project and wanted to leverage existing libraries out  
there, would you manually install them to your iron ruby install  
directory? Or just add them into a gems folder in your project - like  
what merb does with frozen gems?

Regards,  
Glen Cooper  
(425) 802-6627  
[www.glenc.net](http://www.glenc.net)

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 5:58pm UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/5 "2008-08-27T17:58:13Z")

</div>

Normally if you use gems you can wrap the requires in a begin…rescue  
block  
and catch the LoadError. At least that’s how I figured I would do it.  
[http://github.com/casualjim/ironnails/tree/master/IronNails/vendor/iron\_nails/init.rb](http://github.com/casualjim/ironnails/tree/master/IronNails/vendor/iron_nails/init.rb)

I should actually remove those lines now because the libraries are now  
included in the ironruby distribution.

I use a vendor dir where I’ll later first check for any existing folders  
if  
they don’t I’ll try to do the requires of the necessary gems. For  
plugins a  
similar idea is used. I’m looking in the subfolders of vendor or plugins  
for  
a file called init.rb and require those.

What is also done is putting the list of required gems in a readme  
document.

The IronRuby team uses a rake task called happy to see if your  
environment  
is setup properly for the build, I imagine you can do the same.

Certain gems include their dependencies but I personally don’t really  
like  
that approach because often I’ll have the gems already installed  
although it  
makes your gem portable without problems for dependencies.

* * *

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
GSM: +32.486.787.582  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/6 "2008-08-27T17:45:52Z")

</div>

Well rspec for one - but I understand it isn’t quite ready for IR yet

- or vice versa. One of the main reason I’m asking is that I’m  
starting a project which will be a library, not a stand-alone  
application. So I’m wondering about things like dependencies and how  
someone would actually use the library. In other words, if my library  
depends on another, how does the user using my library actually get  
all the dependencies.

I know we’re on the bleeding edge here and there a lot of things that  
either don’t work yet or aren’t as elegant as they will be in the  
future. I am just trying to avoid going down one path if there is a  
better way I’m not aware of.

Thanks for the help!

Glen Cooper  
(425) 802-6627  
[www.glenc.net](http://www.glenc.net)

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/7 "2008-08-27T18:43:58Z")

</div>

In that case I would be very interested to know how to use rspec or any  
of  
the other gems. I tried copying them to the gems folder in the IronRuby  
install folder but that wasn’t it 🙂

I suppose you just took the library and then required the spec file in  
the  
lib folder.

How are you guys doing on rails support because I think I dragged this  
wpf  
chapter out long enough and it’s time to start a new one soon. I was  
thinking rails because I could do my samples for the time being with MRI  
and  
choose some rubygems to showcase.

And my publisher asked me if the date for januari is still good as a  
release  
date 🙂

I have more date questions, do you have an ETA for [asp.net](http://asp.net) & [asp.net](http://asp.net) mvc  
support so I can do some planning around it?  
I realise I could hack something together myself but if that won’t look  
like  
the way you are doing it I would have to rewrite too much in my samples  
probably and it also feels like a waste of time from my part then. I  
guess  
that is not something that can be contributed through the community but  
has  
to come from MS.

Thanks

---

<div class="post-metadata">

**Author:** ![Glen\_Cooper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/9dc877/32.png) [@Glen\_Cooper](https://www.ruby-forum.com/u/Glen_Cooper)\
**Post date:** [August 27, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/looking-for-examples/146964/8 "2008-08-27T18:25:12Z")

</div>

Glen Cooper:

> Well rspec for one - but I understand it isn’t quite ready for IR yet
> 
> - or vice versa.

I’ve actually gotten rspec to run on IronRuby. But today, our startup  
time issues (which are being fixed right now) make it a whole less  
useful than the mspec framework that we’re currently using for testing  
IronRuby.

Thanks,  
-John
