What's new? | Help | Directory | Sign in
Google
                
Search
for
Updated Jul 20, 2007 by R.Vernagus
Labels: Tutorial
UsingBCLTypes  

#How to use .NET BCL types.

How to Use .NET BCL Types

This tutorial demonstrates how to use .NET Base Class Library (BCL) types in Ruby code.

Step 1

Create a file named "bcltypes.rb" with the following content:

require 'mscorlib.dll'
a_date = System::DateTime.new(2007, 1, 1)
puts a_date.AddYears(1).ToString()

The first line is currently required in order to reference BCL core types. Once we have access to the mscorlib library, we can use the DateTime type defined in the System namespace. The second line creates a new instance of the DateTime type which is .NET's core type for representing dates. The last line of code adds a year to our date object and prints the result to the console.

Step 2

Execute the file by typing:

Ruby.exe is Ruby.NET's equivalent of C-Ruby's ruby.exe. In this example, we simply pass the name of our file as a parameter to the executable. When you do this, Ruby.exe will open the file and execute the code contained therein.

Step 3

You should see the following result in the console:

1/1/2008 12:00:00 AM

Comment by DrWayneKelly, Nov 18, 2007

See http://rubydotnet.googlegroups.com/web/Tutorials.htm for more elaborate examples.


Sign in to add a comment