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

BuddyJoe
  • 69,735
  • 114
  • 291
  • 466

2 Answers2

3

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
  • 1,179
  • 7
  • 13
  • thanks +1. Any thoughts to why I can't use arguments on DateTime.new()? see comments to Jon Skeet. – BuddyJoe Sep 29 '09 at 19:48
  • 1
    There are several ways to get there Using the CLR constructor you can do it with Time.clr_new 2007, 6, 5 Using 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 Sep 29 '09 at 21:15
1

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
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 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 – BuddyJoe Sep 25 '09 at 16:07
  • +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. – BuddyJoe Sep 25 '09 at 20:50