Hatena::ブログ(Diary)

はけの徒然日記 このページをアンテナに追加 RSSフィード

2005 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2006 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2007 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2008 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2009 | 01 | 02 | 04 | 05 | 08 | 09 | 10 | 12 |
2010 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 10 | 11 |
2011 | 01 | 02 | 03 | 04 | 11 | 12 |
2012 | 02 | 03 | 05 |

2011-04-30(Sat)

IronRubyの統合開発環境

Visual Studio 2010 Shell

IronRubyは、Visual Studio 2010に対応しているのですが、残念ながらExpress Editionでは使用できないようです。ただし、Microsoft Visual Studio 2010 Shellインストールした後、IronRubyインストールすると新規テンプレートとしてIronRubyが使用できる様になりました。

f:id:hake:20110430170313j:image:small f:id:hake:20110430170312j:image:small

でも、使い方が今ひとつ良く解りません。個人的にはSharpDevelopの方が良さそうです。


SharpDevelop

本体入手はこちらから最新バージョンは4.0です。インストールしたPCには.Net 4.0のみしか無かった為にインストール時に.Net 3.5sp1 runtimeを要求されましたのでダウンロードページにあったリンクから入手。

日本語化リソースは、こちらから入手。現時点でSharpDevelop 4.0用の日本語リソースは公開されていませんが、3.2用を使用しても問題なさそうです。


f:id:hake:20110430170314j:image:small f:id:hake:20110430170315j:image:small


なおソース上での日本語コードは、CP932ではなくUTF-8になるので1行目の指定には間違えないようにする必要あり。

# coding: utf-8

IronRubyを試してみる

インストールしたのは、こちらの最新版の1.1.3(ruby 1.9.2ベース

>ir -v
IronRuby 1.1.3.0 on .NET 4.0.30319.225

.NETの作法がまったく分からないので、こちらソースを参考にさせて頂き、1行目に文字コード指定を追記、ソース内の文字列日本語にしてみました。

stable(v1.0)版(ruby 1.8.6ベース)では日本語表示が上手くいかない様ですが、v1.1.3では問題なく表示するようですね。

f:id:hake:20110430065042j:image



ソース

# coding: Windows-31J
require 'mscorlib'
require 'System.Windows.Forms'
require 'System.Drawing'

class RubyForm < System::Windows::Forms::Form

  def initialize
    self.text = "ウィンドウズフォーム on IronRuby"
    btn = System::Windows::Forms::Button.new
    btn.location = System::Drawing::Point.new(50, 50)
    btn.text = "クリック!"

    btn.click{|sender, e|
      System::Windows::Forms::MessageBox.show("ハロー IronRuby!")
    }
    
    controls.add(btn)
  end

end

System::Windows::Forms::Application.run(RubyForm.new) 

# coding: Windows-31J
require 'mscorlib'
require 'System.Windows.Forms'
require 'System.Drawing'

class RubyForm < System::Windows::Forms::Form

  def initialize
    self.text = "ウィンドウズフォーム on IronRuby"
    @btn = System::Windows::Forms::Button.new
    @btn.location = System::Drawing::Point.new(50, 50)
    @btn.text = "クリック!"
    @btn.click do |sender, e| btn_click(sender, e) end

    controls.add(@btn)
  end

  def btn_click(sender, e)
      p sender.class  # => System::Windows::Forms::Button
      p sender.text.encode('Windows-31J') # => "クリック!"
      p e.class       # => System::Windows::Forms::MouseEventArgs

      System::Windows::Forms::MessageBox.show("ハロー IronRuby!")
  end
end

System::Windows::Forms::Application.run(RubyForm.new)