views:

322

answers:

2

When I embed IronRuby what is the proper way to get a reference to either Ruby's DateTime/Date classes or .NET's System.DateTime. I'm running into errors when I try

require 'date'

I get the error - no such file to load -- date

when I try require 'mscorlib.dll' I get the error - no such file to load -- mscorlib.dll

What is the right way to do either of these?

UPDATE: see comments to Jon Skeet

+1  A: 

Have you tried

require 'mscorlib'

to specify the assembly name instead of the filename? That's what's specified in this old blog post...

Jon Skeet
that got me a little farther. Now I just choking on dt = System::DateTime.new(2007,6,5). Gives wrong number of arguments (3 for 0). hmmmmm
tyndall
+1. Still stuck on the .new constructor blowing up though. Never did solve it. Had to create a CreateDateTime() method off of one of my objects just so I could workaround this for now.
tyndall
+2  A: 

Time is a core type in ruby which maps to a System.DateTime.

To get DateTime.Now you can do Time.new

There are datetime extensions so you could do require 'time' or require 'datetime'

mscorlib is implied and is always required so you don't need to explicitly require it. if you want to get to the CLR DateTime you can do

System::DateTime.now or System::DateTime.Now

Casual Jim
thanks +1. Any thoughts to why I can't use arguments on DateTime.new()? see comments to Jon Skeet.
tyndall
There are several ways to get there Using the CLR constructor you can do it with Time.clr_new 2007, 6, 5Using the ruby method for a local time you can use Time.local 2007, 6, 5 and for utc you use Time.utc 2007, 6, 5
Casual Jim
clr_new huh. will have to read up on that. thanks again.
tyndall