RubyForWindows


Ruby for Windows

link


Idioms

Rubyイディオム

1.ファイルを読み込んで処理をする。

(1) 各行の処理 Yugui(2008.6)「初めてのRuby」 オライリー・ジャパン  p.89
File.open("data.txt"){|f|
f.each_line do |line|
print "#{f.lineno}: #{line}"
end
}

(2)各行の処理 高橋他(2006) 「たのしいRuby第2版」ソフトバンク クリエティブ p.285,289
open("foo.txt"){|io|
while line=io.gets
line.chomp! # 行末の改行を取り除く。
...
end
}

(3)ファイル内容を一度に取りこむ Yugui(2008) p.86
File.open("data.txt"){|f|
contens=f.read 
print contents
}

(4)ファイル内容を一度に取りこみ、各行を要素とする配列を返す。
 f.readlines

2.ファイル名を引数として取りこむ
(1)第1引数で 高橋他(2006.8) p.50
filename = ARGV[0]
file = open(filename)
.....
file.close

(2)複数ファイルを指定し、ファイル内容をとりこむ Yugui(2008) p.92
ARGF.each_line do |line|
print line
end
(引数がなければ、標準入力から読み込む)


print "あなたのお名前はなんですか:"
name = STDIN.gets
puts "お名前は#{name.chomp}さんですね。"

install

  • OneClickInstaller 1.8.6をinstall(2008.9.13) c:\ruby
  • RubyGems1.2.0をinstall (extactし、ruby setup.rb)
    • gem update --systemでうまくいかなかったため。
  • RubyGemsの使い方 http://webos-goodies.jp/archives/51106257.html
  • Install後の更新履歴
       Ruby Installer for Windows
      Ruby Version 1.8.6
      Installer Version 186-26
    ------------------------------
         RELEASE NOTES
    ------------------------------
    Contents:           Version:
    --------            --------
     ruby-mswin32        ruby-1.8.6-p111
     zlib-lib            1.2.3
     ZLib                0.6.0
     RubyGems            0.9.4  => 1.2.0
     Rake                0.7.3
     RubySrc             1.8.6-p111
     OpenSSL             0.9.8d
     FXRuby              1.6.12
     FXri                0.3.6
     SciTE               1.72
     OpenGL              0.50.0
     GLUT                3.7.6
     SWin                070409
     VRuby               061102
     Expat               2.0.0
     Hpricot             0.6
     RubyDBI             0.1.1
     DBD/ODBC            0.9995
     win32-api           1.0.4
     windows-api         0.2.0
     windows-pr          0.7.2
     win32-file-stat     1.2.7
     win32-file          0.5.4
     win32-clipboard     0.4.3
     win32-dir           0.3.2
     win32-eventlog      0.4.6
     win32-process       0.5.3
     win32-sapi          0.1.4
     win32-sound         0.4.1
     log4r               1.0.5
     Programming Ruby    1st Edition
     libfcgi             2.4.0
     ruby-fcgi           0.8.7
     Iconv               1.8
     readline            4.3-2
     PDCurses            2.60-1
     GDBM                1.8.3-1
     Installer-Patches   1.8.6


@echo off
c:\usr\local\ruby-1.8\bin\ruby.exe  c:\usr\local
   \ruby-1.8\bin\rd2 %1 %2 %3 %4 %5 %6 %7 %8 %9
@echo off
c:\usr\local\ruby-1.8\bin\ruby.exe c:\usr\local\ruby-1.8
   \bin\rt2 %1 %2 %3 %4 %5 %6 %7 %8 %9
forkが実装されていないといって、エラーとなる。

rake


解説等




#bf
Copyright T.Osawa 2008-
最終更新:2009年05月20日 14:11
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。