标签: IronRuby

  • IronRuby一些小技巧

    操作excel

     1: require "Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 

     2:  

     3: include Microsoft::Office::Interop::Excel

     4: excel = ApplicationClass.new

     5: excel.Visible = true

     6: workbook = excel.Workbooks.Add()

     7: worksheet = workbook.Worksheets.Add()

     8: worksheet.Name = "aaaaa" 

     9:  

     10: cell1 = worksheet.Cells(1,1)

     11: cell1.Value = 42

    如何获得assembly的strong name?

     1: load_assembly 'Microsoft.Office.Interop.Excel'

     2:  

     3: System::AppDomain.current_domain.get_assemblies.each{|x| puts x};

    RPC 解决方案(http://www.ruby-forum.com/topic/206314

    Very CLR centric:

    You can create a proxy to your webservice using visual studio, compile to a dll and use the proxy from your ruby code.

    CLR centric:

    You can use System.Net.HttpWebRequest to make the request and System.Xml.XmlDocument to parse the response

    Very Ruby centric:

    Use Net::HTTP to perform the request and REXML to parse the response

  • IronRuby试玩

    IronRuby下载最新版本解压,然后把目录加入系统Path。

    IronRuby使用Sinatra

    1)igem install sinatra –no-rdoc –no-ri

    2) 应该提示rack和sinatra都安装完毕

    3)写代码如下:

     1: require 'rubygems'

     2: require 'sinatra' 

     3: get '/' do

     4: "My machine name is #{System::Environment::machine_name}"

     5: end

    保存为mysinatra1.rb

    4) 运行 ir mysinatra1.rb,应该提示类似pid=xxxx port=4567,打开浏览器,输入http://localhost:4567/ 就可以看到期望的信息了。

    注意,在我测试过程中,最新版本下,不需要对sinatra做任何patch,跟ironruby官网提到的不一样。

    IronRuby使用Rails,参考http://www.ironruby.net/Documentation/Real_Ruby_Applications/Rails

    1)安装 "igem install rake rails activerecord-adonet-sqlserver –no-rdoc –no-ri"

    2)如果自己测试,可使用sqlite3-ironruby,"igem install sqlite3-ironruby –no-ri –no-rdoc”

    3)建立一个IronRuby rail程序, "ir -S rails IronFirst"

    4)修改config/environment.rb,可以看到有类似的代码,改成 config.gem "sqlite3-ironruby", :lib => "sqlite3" ,使用sqlserver有另外的修改方式,大家自己看网页吧。

    5)ir script\generate scaffold post title:string body:text published:boolean

        ir -S rake db:migrate

    6)ir script\server

    这时候可以看到http://localhost:3000 是rails的默认界面,进入http://localhost:3000/posts 可以进行添删改操作。不过我测试,默认下不支持中文,应该是要修改一些参数才行。

    all done.