Browse | Submit A New Snippet | Create A Package

 

Running ruby apps using iron ruby.

Type:
Sample Code (HOWTO)
Category:
Other
License:
GNU General Public License
Language:
C#
 
Description:
Running ruby using iron ruby.

Versions Of This Snippet::

Mahesh Sawaiker
Snippet ID Download Version Date Posted Author Delete
4311.02009-01-05 12:27Mahesh Sawaiker

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :1.0

Compile the code by getting it from the svn repository. You will need .net 3.0 framework and C# express edition 2008 for this. The details to download are given on the project page in ruby for iron ruby. The code is neatly packaged as a visual studio 2008 solution.

The solution has a console application project, run the output ir.exe on command line with following input. 

upon typing ir ->Enter in the command prompt u will get the following output

************************************************************************************************
E:\Program Files\CollabNet Subversion\ironruby\tags\ironruby_10_alpha_2\build\de
bug>ir
IronRuby 1.0.0.2 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).

>>>

*************************************************************************************************
at the prompt type 2.times do puts 'hi' end and press enter
******************************************************************************
>>> 2.times do puts 'hi' end
hi
hi
=> 2
>>>

*************guess that is enough for getting started*************************
I have tried some fancy things with proc and except some things it handles most things. You can also enter a file with ir <filename>
you can try the file below for some fun. It works completely with ruby but not with Iron ruby just to get an idea


=begin
set_trace_func proc { |event, file, line, id, binding, classname|
  printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
}
=end
require 'drb'
def gettimes(factor)
	return Proc.new{|n| n*factor }
end

times3 = gettimes(3)
times5 = gettimes(5)

puts "3 times 4 is "+times3.call(4).to_s
puts "5 times 10 is "+times5.call(10).to_s


def proc_from
	theVariable = 10
	Proc.new
end

sayHelloProc = proc_from { 
							3.times do puts "hello" end
							puts "is there any body in there"
					
						 }

sayHelloProc.call
puts times3[50]

puts "*****ARITY TEST****************"
puts "Proc.new {||}.arity \n  	
Proc.new {|a|}.arity \n	
Proc.new {|a,b|}.arity\n	
Proc.new {|a,b,c|}.arity\n 	
Proc.new {|*a|}.arity 	\n
Proc.new {|a,*b|}.arity 	"

puts Proc.new {||}.arity   	
puts Proc.new {|a|}.arity 	
puts Proc.new {|a,b|}.arity 	
puts Proc.new {|a,b,c|}.arity
puts Proc.new {|*a|}.arity 	
puts Proc.new {|a,*b|}.arity 

def double(a)
  2*a
end
mObj = method(:double)
p [ 1, 3, 5, 7 ].collect(&mObj)

trane = %q{puts "John Coltrane".length}
eval trane


************************************************************************************
Following are some useful links
http://www.ironruby.net/
http://rubyforge.org/projects/ironruby/

		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..