SlideShare a Scribd company logo
1 of 31
オブジェクト指向スクリプト言語

     Ruby
agenda
•   Ruby とは…
•   Ruby の歴史
•   Ruby 1.9.1 について
•   Windows で Ruby をコンパイル
Ruby とは…
•   オブジェクト指向スクリプト言語
•   シンプルで読みやすい文法
•   優れたテキスト処理能力
•   作者が日本人
    – まつもと ゆきひろ 氏
• Perl に代わる(かもしれない)言語
    – 名前の由来的な意味で
• Ruby on Rails の登場で一躍有名に
• 完成はまだまだ先の言語
Ruby のバージョン番号
• バージョン確認コマンド
   > ruby –v
   > ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mswin32_90]

• Ruby 1.2~1.8 まで
   – 安定版:Minor が偶数
                                         ruby 1.8.6
   – 開発版:Minor が奇数
• Ruby 1.9
   – 安定版:Teeny が 0 以外
   – 開発版:Teeny が 0                               Major   Minor   Teeny


• 最新安定版は Ruby 1.9.1-p0(2009/04/27 現在)
Ruby 2.0
•   コードネーム Rite
•   「いつか手に入れられる理想の Ruby」
•   いつ出るかは分からない
•   いくつかの機能は 1.9 で実装されはじめて
    いる(M17N・GC など)
Ruby の歴史 (1/3)
  年    月日                           出来事
       12/18 Perl の誕生日
1987
       03/21 Perl 4 初リリース
1991
       02/24 Ruby の誕生日
1993
       10/18 Perl 5 初リリース
1994
       11/23 Windows 95 日本語版発売
1995
               Apache 初リリース
       04/--
               Ruby 0.95 がはじめて日本のニュースグループに投稿される
       12/--
       12/25 Ruby 1.0 クリスマスリリース
1996
               Ruby 1.1 リリース
1997   08/--
               Ruby 1.2, 1.3 リリース
1998   12/--
               日本で ADSL サービス開始
2000   --/--
Ruby の歴史(2/3)
  年    月日                               出来事
       09/01 Yahoo! BB サービス開始
2001
       12/25 Ruby 1.6.8 クリスマスリリース
2002
       08/04 Ruby 1.8.0 リリース
2003
       12/01 Ruby 1.8.1 リリース
       07/25 Ruby on Rails 初リリース
2004
       12/25 Ruby 1.8.2 クリスマスリリース
2005 09/21 Ruby 1.8.3 リリース
       12/13 Ruby on Rails 1.0.0 リリース
       03/28 Ruby on Rails 1.1.0 リリース
2006
       08/25 Ruby 1.8.5 リリース
       01/18 Ruby on Rails 1.2.0 リリース
2007
Ruby の歴史(3/3)
  年    月日                               出来事
       03/13 Ruby 1.8.6 リリース
2007
       11/24 Ruby on Rails 1.2.6 リリース
       12/06 Ruby on Rails 2.0.0 リリース
       12/26 Ruby 1.9.0 リリース「日付変わっちゃった」
       05/31 Ruby on Rails 2.1.0 リリース
2008
       06/01 Ruby 1.8.7 リリース
       11/21 Ruby on Rails 2.2.2 リリース
               Ruby 1.9.1 リリース延期
       12/--
       01/31 Ruby 1.9.1 リリース
2009
       03/15 Ruby on Rails 2.3.2 リリース
       05/07 Ruby on Rails 3 beta リリースはやっぱ無理でした
Ruby の将来
• Ruby 1.8.7 から徐々に Ruby 1.9 系へシフト
• Ruby 1.8 系の開発も継続
 – 年内にも Ruby 1.8.8 リリースか
Ruby 1.6.8 → 1.8.0 の変更点
• 文法の変更
• メソッドの追加
• 拡張ライブラリ API の追加
 – YAML, zlib, erb, WEBrick, etc…
Ruby 1.8.6 → Ruby 1.9.1 の変更点
• YARV の実装
• M17N 対応
• 組み込みクラス、メソッドの変更
 – Hash, Enumerator, etc…
• 文法の変更
• ライブラリの拡張
• 省メモリ化
YARV
• Ruby 言語処理系仮想マシン
• Yet Another Ruby VM
 – もう Yet Another ではない
• 高速化
 – 但し普通の Ruby 文に限る
 – 正規表現や拡張ライブラリには効果なし
                                 バイトコード
                  AST※
  Ruby                                    Ruby 1.9
                         コンパイル
                                           実行

                                          Ruby 1.8
                                           実行
 ※AST : Abstract Syntax Tree(抽象構文木)
M17N(1/2)
              17 文字


•   MultilingualizatioN
•   多言語化、マルチリンガル化
•   内部言語を持たない
•   Magic Comment
    – 正規表現で /coding[:=]s*[w.-]+/
    #   -*- coding: utf-8 -*-
    #   vim:fileencoding=utf-8
    #   vim:set fileencoding=utf-8 :
    #   coding: UTF-8

    – ソースコードに非 ASCII なリテラルが含まれる
      場合は必須
         • 日本語の変数名も使える
M17N(2/2)
• 文字列1つずつが Encoding 情報を持つ
    # coding: UTF-8
    “あいうえお”.encoding #=> #<Encoding:UTF-8>

• String#[], String#length
    – 1文字1単位
   Ruby 1.8.6 “あいうえお”[0] #=> 130
              “あいうえお”.length #=> 10

   Ruby 1.9.1 “あいうえお”[0] #=> “あ”
              “あいうえお”.length #=> 5
              “あいうえお”.bytesize #=> 10

• 詳しくは「るびま」0025 号で!
    – String が Enumerable ではなくなった
    – Regexp(鬼車)
    – 文字列の比較・結合
組み込みクラス、メソッドの変更
•   Enumerator
•   Hash の拡張
•   tap
•   Symbol#to_proc
    – ary.inject(:&+) #=> ary.inject{|r, e| r + e}
• to_s の書式変更
• Array の拡張
    – Array#permutation, Array#product,
      Array#shuffle, Array#flatten, Array#drop,
      Array#simple, Array#take
組み込みクラス、メソッドの変更

                           Enumerator
• 組み込みクラスになった
• イテレータっぽいメソッドをブロック
  なしで呼び出すと Enumerator を返す
 1.times #=> <Enumerator>

 Ruby 1.8.6 require ‘enumerator’
            a = []
            [1, 2, 3].each_cons(2) do |x, y|
              a << [x, y]
            end
            a.map {|x, y| x*y} #=> [2, 6]
 Ruby 1.9.1 a = [1, 2, 3].each_cons(2).map {|x, y| x*y} #=> [2, 6]
組み込みクラス、メソッドの変更

                          Hash の拡張
• Ordered Hash
  – Hash が順序を保存するようになった
 Ruby 1.8.6
              p h={:a => 1, :b => 2, :c => 3}
              #=> {:b => 2, ={:a => 1, :c => 3}

 Ruby 1.9.1 p h={:a => 1, :b => 2, :c => 3}
              #=> {:a => 1, :b => 2, :c => 3}


• Hash リテラルの拡張
 Ruby 1.8.6
              {:a => 1, :b => 2, …}
              foo(:a =>, :b => 2) #キーワード引数もどき

 Ruby 1.9.1 {a: 1, b:2, …}
              foo(a: 1, b: 2) #キーワード引数もどき
組み込みクラス、メソッドの変更

  その他話題に挙がっていた物
• tap
 Ruby 1.9.1 p [1,2,3].map{|x| x**2}.tap{|a| p a}.select{|x| x>5}
            #=>[1, 4, 9]
            # [9]



• Symbol#to_proc
  – ary.inject(:&+) #=> ary.inject{|r, e| r + e}
• to_s の書式変更
 Ruby 1.8.6
              puts h={“hoge”=10, “huga”=>20}
              #=> hoge10huga20

 Ruby 1.9.1 puts h={“hoge”=10, “huga”=>20}
              #=> {“hoge”=10, “huga”=>20}
文法の変更(1/2)
• ブロックパラメータの変更
 – オプショナル引数などが利用可能
• ブロックスコープの変更
 Ruby 1.8.6 x = 1
            loop {|x| x = 0; break}
            px
            #=> warning: multiple values for a block parameter
            #0
 Ruby 1.9.1 x = 1
            loop {|x| x = 0; break}
            px
            #=> 1
文法の変更(2/2)
• Post Argument
  Ruby 1.8.6 def foo(front, *temp, last)
             end
             #=> Syntax Error
  Ruby 1.9.1 def foo(front, *temp, last)
             end
             #=> OK


• splat(配列展開)
  Ruby 1.8.6 puts(*ary1, *ary2)
             #=> Syntax Error
  Ruby 1.9.1 puts(*ary1, *ary2)
             #=> OK
ライブラリの拡張
• RubyGems の取り込み
• Rake の取り込み
省メモリ化
• 省メモリ化
 – 標準クラス String, Array, Hash など
 – 性能よりもメモリ使用量削減に力を
• GC の改良
Ruby 1.9.1 まとめ
• いろいろ便利な機能が追加された
• 性能向上が期待できる
Ruby 1.8.6 → 1.8.7
• Ruby 1.9 からのバックポート多数
 – Enumerator
 – Array の拡張
 – tap
 – その他新規メソッドの追加
Windows で Ruby をコンパイル
• 環境
  – OS: Windows XP SP3 & Windows Vista SP1
  – Compiler: Visual C++ 2008 Express Edition(無料)
• Ruby
  – Ruby 1.8.6 p368
  – Ruby 1.8.7 p160
  – Ruby 1.9.1 p0
Ruby のコンパイル
• 公式からソースを ダウンロード, 解凍
• VC++ のコマンドプロンプトを起動
• ソースフォルダに移動して
  C:ruby-1.8.7-p160>cd win32
  C:ruby-1.8.7-p160win32>configure.bat
  C:ruby-1.8.7-p160win32>nmake
  C:ruby-1.8.7-p160win32>nmake DESTDIR=C:/Ruby install


• Ruby 1.9.1 は
  C:ruby-1.9.1-p0>cd win32
  C:ruby-1.9.1-p0win32>configure.bat --prefix=C:/Ruby
  C:ruby-1.9.1-p0win32>nmake
  C:ruby-1.9.1-p0win32>nmake install
拡張ライブラリのコンパイル
• 拡張ライブラリの Win32 用 バイナリを
  ダウンロード or コンパイル
 – 必要な物はバイナリ(DLL ファイル)と
   ヘッダファイルと *.lib ファイル
• ext フォルダ内の目的の拡張ライブラリ
  フォルダに移動
• extconf.rb を使って Makefile を作成
• *.so ファイルが出来れば OK
• ruby.exe のあるフォルダに
  DLL ファイルをコピー
例:zlib のコンパイル
• zlib-1.1.4-1 バイナリ作成
  C:zlib-1.1.4-1>cd win32
  C:zlib-1.1.4-1>nmake
  C:zlib-1.1.4-1>mt –manifest zlib.dll.manifest –outputsource:zlib.dll;2
  C:zlib-1.1.4-1>copy zlib.dll C:/Ruby/bin



• Ruby にインストール
  C:ruby-1.8.7-p160>cd extzlib
  C:ruby-1.8.7-p160extzlib>ruby extconf.rb --with-zlib-include=C:zlib-
  1.1.4-1include --with-zlib-lib=C:zlib-1.1.4-1lib
  C:ruby-1.8.7-p160win32>nmake
  C:ruby-1.8.7-p160win32>nmake install
  ※ ruby にパスが通ってないと extconf.rb は実行できない
詰みポイント
• openssl
   – extconf.rb が吐いた Makefile の中にある
     CFLAGS のパラメータを変更しないとエラー
      CFLAGS = -MD -O2b2xty-
      CFLAGS = -MD -DWIN32_LEAN_AND_MEAN -O2b2xty-


• zlib 1.2.3
   – Windows 版では謎の挙動(バグ?)を
     するため gem でエラーが起きる
   – 回避するためにはパッチを当てる必要がある
      • Bug#888 [Ruby-core:20576]
   – zlib 1.1.4-1 では gem 側に回避する措置がとられてい
     るのでエラーは起きない
その他の mswin32 版 Ruby
•   One-Click Installer
     – Ruby 1.8.6
     – インストーラ付き
•   InstantRails
     – Ruby 1.8.6 with Rails
     – Apache
     – MySQL
•   ActiveScriptRuby
     – Ruby 1.8.7
     – ActiveScript で Ruby が使える
     – その他必要なもの一通りセット
•   Rumix
     – Ruby 1.8.7
     – インストーラ付き
•   Ruby-mswin32 (ja)
     – Ruby 1.9.1 までの各種バージョン
     – 手動インストール
今後の予定
• Ruby on Rails or Merb を使って Web 開発

More Related Content

Similar to オブジェクト指向スクリプト言語 Ruby

20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編mochiko AsTech
 
20090323 Phpstudy
20090323 Phpstudy20090323 Phpstudy
20090323 PhpstudyYusuke Ando
 
Ruby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese VersionRuby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese VersionLibin Pan
 
Chinaonrails Rubyonrails21 Zh
Chinaonrails Rubyonrails21 ZhChinaonrails Rubyonrails21 Zh
Chinaonrails Rubyonrails21 ZhJesse Cai
 
20090410 Gree Opentech Presentation (opening)
20090410 Gree Opentech Presentation (opening)20090410 Gree Opentech Presentation (opening)
20090410 Gree Opentech Presentation (opening)Hideki Yamane
 
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説mochiko AsTech
 
20090410 Gree Opentech Main
20090410 Gree Opentech Main20090410 Gree Opentech Main
20090410 Gree Opentech MainHideki Yamane
 
Ruby on Rails Tutorial Part I
Ruby on Rails Tutorial Part IRuby on Rails Tutorial Part I
Ruby on Rails Tutorial Part IWei Jen Lu
 
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信Yusuke Kawasaki
 
Where20 2009report
Where20 2009reportWhere20 2009report
Where20 2009reportToru Mori
 
とちぎRuby会議01(原)
とちぎRuby会議01(原)とちぎRuby会議01(原)
とちぎRuby会議01(原)Shin-ichiro HARA
 
Gorm @ gopher china
Gorm @ gopher chinaGorm @ gopher china
Gorm @ gopher chinaJinzhu
 
英語ブログのスヽメ - 1000スピーカープロジェクト#5
英語ブログのスヽメ - 1000スピーカープロジェクト#5英語ブログのスヽメ - 1000スピーカープロジェクト#5
英語ブログのスヽメ - 1000スピーカープロジェクト#5Yusuke Kawasaki
 
企业级搜索引擎Solr交流
企业级搜索引擎Solr交流企业级搜索引擎Solr交流
企业级搜索引擎Solr交流chuan liang
 
How To Create Custom DSLs By PHP
How To Create Custom DSLs By PHPHow To Create Custom DSLs By PHP
How To Create Custom DSLs By PHPAtsuhiro Kubo
 
Sc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク DomaSc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク DomaToshihiro Nakamura
 
【12-B-4】 並列処理開発を支援するコンパイラの機能
【12-B-4】 並列処理開発を支援するコンパイラの機能【12-B-4】 並列処理開発を支援するコンパイラの機能
【12-B-4】 並列処理開発を支援するコンパイラの機能devsumi2009
 

Similar to オブジェクト指向スクリプト言語 Ruby (20)

20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編20090418 イケテルRails勉強会 第1部Rails編
20090418 イケテルRails勉強会 第1部Rails編
 
20090323 Phpstudy
20090323 Phpstudy20090323 Phpstudy
20090323 Phpstudy
 
Ruby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese VersionRuby on Rails 2.1 What's New Chinese Version
Ruby on Rails 2.1 What's New Chinese Version
 
Chinaonrails Rubyonrails21 Zh
Chinaonrails Rubyonrails21 ZhChinaonrails Rubyonrails21 Zh
Chinaonrails Rubyonrails21 Zh
 
20090410 Gree Opentech Presentation (opening)
20090410 Gree Opentech Presentation (opening)20090410 Gree Opentech Presentation (opening)
20090410 Gree Opentech Presentation (opening)
 
dRuby
dRubydRuby
dRuby
 
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説
 
20090410 Gree Opentech Main
20090410 Gree Opentech Main20090410 Gree Opentech Main
20090410 Gree Opentech Main
 
Ruby on Rails Tutorial Part I
Ruby on Rails Tutorial Part IRuby on Rails Tutorial Part I
Ruby on Rails Tutorial Part I
 
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
Cloud era -『クラウド時代』マッシュアップ技術による地方からの世界発信
 
Where20 2009report
Where20 2009reportWhere20 2009report
Where20 2009report
 
rails-footnotes
rails-footnotesrails-footnotes
rails-footnotes
 
とちぎRuby会議01(原)
とちぎRuby会議01(原)とちぎRuby会議01(原)
とちぎRuby会議01(原)
 
Gorm @ gopher china
Gorm @ gopher chinaGorm @ gopher china
Gorm @ gopher china
 
英語ブログのスヽメ - 1000スピーカープロジェクト#5
英語ブログのスヽメ - 1000スピーカープロジェクト#5英語ブログのスヽメ - 1000スピーカープロジェクト#5
英語ブログのスヽメ - 1000スピーカープロジェクト#5
 
sigfpai73-kaji
sigfpai73-kajisigfpai73-kaji
sigfpai73-kaji
 
企业级搜索引擎Solr交流
企业级搜索引擎Solr交流企业级搜索引擎Solr交流
企业级搜索引擎Solr交流
 
How To Create Custom DSLs By PHP
How To Create Custom DSLs By PHPHow To Create Custom DSLs By PHP
How To Create Custom DSLs By PHP
 
Sc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク DomaSc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク Doma
 
【12-B-4】 並列処理開発を支援するコンパイラの機能
【12-B-4】 並列処理開発を支援するコンパイラの機能【12-B-4】 並列処理開発を支援するコンパイラの機能
【12-B-4】 並列処理開発を支援するコンパイラの機能
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

オブジェクト指向スクリプト言語 Ruby

  • 2. agenda • Ruby とは… • Ruby の歴史 • Ruby 1.9.1 について • Windows で Ruby をコンパイル
  • 3. Ruby とは… • オブジェクト指向スクリプト言語 • シンプルで読みやすい文法 • 優れたテキスト処理能力 • 作者が日本人 – まつもと ゆきひろ 氏 • Perl に代わる(かもしれない)言語 – 名前の由来的な意味で • Ruby on Rails の登場で一躍有名に • 完成はまだまだ先の言語
  • 4. Ruby のバージョン番号 • バージョン確認コマンド > ruby –v > ruby 1.8.6 (2009-03-31 patchlevel 368) [i386-mswin32_90] • Ruby 1.2~1.8 まで – 安定版:Minor が偶数 ruby 1.8.6 – 開発版:Minor が奇数 • Ruby 1.9 – 安定版:Teeny が 0 以外 – 開発版:Teeny が 0 Major Minor Teeny • 最新安定版は Ruby 1.9.1-p0(2009/04/27 現在)
  • 5. Ruby 2.0 • コードネーム Rite • 「いつか手に入れられる理想の Ruby」 • いつ出るかは分からない • いくつかの機能は 1.9 で実装されはじめて いる(M17N・GC など)
  • 6. Ruby の歴史 (1/3) 年 月日 出来事 12/18 Perl の誕生日 1987 03/21 Perl 4 初リリース 1991 02/24 Ruby の誕生日 1993 10/18 Perl 5 初リリース 1994 11/23 Windows 95 日本語版発売 1995 Apache 初リリース 04/-- Ruby 0.95 がはじめて日本のニュースグループに投稿される 12/-- 12/25 Ruby 1.0 クリスマスリリース 1996 Ruby 1.1 リリース 1997 08/-- Ruby 1.2, 1.3 リリース 1998 12/-- 日本で ADSL サービス開始 2000 --/--
  • 7. Ruby の歴史(2/3) 年 月日 出来事 09/01 Yahoo! BB サービス開始 2001 12/25 Ruby 1.6.8 クリスマスリリース 2002 08/04 Ruby 1.8.0 リリース 2003 12/01 Ruby 1.8.1 リリース 07/25 Ruby on Rails 初リリース 2004 12/25 Ruby 1.8.2 クリスマスリリース 2005 09/21 Ruby 1.8.3 リリース 12/13 Ruby on Rails 1.0.0 リリース 03/28 Ruby on Rails 1.1.0 リリース 2006 08/25 Ruby 1.8.5 リリース 01/18 Ruby on Rails 1.2.0 リリース 2007
  • 8. Ruby の歴史(3/3) 年 月日 出来事 03/13 Ruby 1.8.6 リリース 2007 11/24 Ruby on Rails 1.2.6 リリース 12/06 Ruby on Rails 2.0.0 リリース 12/26 Ruby 1.9.0 リリース「日付変わっちゃった」 05/31 Ruby on Rails 2.1.0 リリース 2008 06/01 Ruby 1.8.7 リリース 11/21 Ruby on Rails 2.2.2 リリース Ruby 1.9.1 リリース延期 12/-- 01/31 Ruby 1.9.1 リリース 2009 03/15 Ruby on Rails 2.3.2 リリース 05/07 Ruby on Rails 3 beta リリースはやっぱ無理でした
  • 9. Ruby の将来 • Ruby 1.8.7 から徐々に Ruby 1.9 系へシフト • Ruby 1.8 系の開発も継続 – 年内にも Ruby 1.8.8 リリースか
  • 10. Ruby 1.6.8 → 1.8.0 の変更点 • 文法の変更 • メソッドの追加 • 拡張ライブラリ API の追加 – YAML, zlib, erb, WEBrick, etc…
  • 11. Ruby 1.8.6 → Ruby 1.9.1 の変更点 • YARV の実装 • M17N 対応 • 組み込みクラス、メソッドの変更 – Hash, Enumerator, etc… • 文法の変更 • ライブラリの拡張 • 省メモリ化
  • 12. YARV • Ruby 言語処理系仮想マシン • Yet Another Ruby VM – もう Yet Another ではない • 高速化 – 但し普通の Ruby 文に限る – 正規表現や拡張ライブラリには効果なし バイトコード AST※ Ruby Ruby 1.9 コンパイル 実行 Ruby 1.8 実行 ※AST : Abstract Syntax Tree(抽象構文木)
  • 13. M17N(1/2) 17 文字 • MultilingualizatioN • 多言語化、マルチリンガル化 • 内部言語を持たない • Magic Comment – 正規表現で /coding[:=]s*[w.-]+/ # -*- coding: utf-8 -*- # vim:fileencoding=utf-8 # vim:set fileencoding=utf-8 : # coding: UTF-8 – ソースコードに非 ASCII なリテラルが含まれる 場合は必須 • 日本語の変数名も使える
  • 14. M17N(2/2) • 文字列1つずつが Encoding 情報を持つ # coding: UTF-8 “あいうえお”.encoding #=> #<Encoding:UTF-8> • String#[], String#length – 1文字1単位 Ruby 1.8.6 “あいうえお”[0] #=> 130 “あいうえお”.length #=> 10 Ruby 1.9.1 “あいうえお”[0] #=> “あ” “あいうえお”.length #=> 5 “あいうえお”.bytesize #=> 10 • 詳しくは「るびま」0025 号で! – String が Enumerable ではなくなった – Regexp(鬼車) – 文字列の比較・結合
  • 15. 組み込みクラス、メソッドの変更 • Enumerator • Hash の拡張 • tap • Symbol#to_proc – ary.inject(:&+) #=> ary.inject{|r, e| r + e} • to_s の書式変更 • Array の拡張 – Array#permutation, Array#product, Array#shuffle, Array#flatten, Array#drop, Array#simple, Array#take
  • 16. 組み込みクラス、メソッドの変更 Enumerator • 組み込みクラスになった • イテレータっぽいメソッドをブロック なしで呼び出すと Enumerator を返す 1.times #=> <Enumerator> Ruby 1.8.6 require ‘enumerator’ a = [] [1, 2, 3].each_cons(2) do |x, y| a << [x, y] end a.map {|x, y| x*y} #=> [2, 6] Ruby 1.9.1 a = [1, 2, 3].each_cons(2).map {|x, y| x*y} #=> [2, 6]
  • 17. 組み込みクラス、メソッドの変更 Hash の拡張 • Ordered Hash – Hash が順序を保存するようになった Ruby 1.8.6 p h={:a => 1, :b => 2, :c => 3} #=> {:b => 2, ={:a => 1, :c => 3} Ruby 1.9.1 p h={:a => 1, :b => 2, :c => 3} #=> {:a => 1, :b => 2, :c => 3} • Hash リテラルの拡張 Ruby 1.8.6 {:a => 1, :b => 2, …} foo(:a =>, :b => 2) #キーワード引数もどき Ruby 1.9.1 {a: 1, b:2, …} foo(a: 1, b: 2) #キーワード引数もどき
  • 18. 組み込みクラス、メソッドの変更 その他話題に挙がっていた物 • tap Ruby 1.9.1 p [1,2,3].map{|x| x**2}.tap{|a| p a}.select{|x| x>5} #=>[1, 4, 9] # [9] • Symbol#to_proc – ary.inject(:&+) #=> ary.inject{|r, e| r + e} • to_s の書式変更 Ruby 1.8.6 puts h={“hoge”=10, “huga”=>20} #=> hoge10huga20 Ruby 1.9.1 puts h={“hoge”=10, “huga”=>20} #=> {“hoge”=10, “huga”=>20}
  • 19. 文法の変更(1/2) • ブロックパラメータの変更 – オプショナル引数などが利用可能 • ブロックスコープの変更 Ruby 1.8.6 x = 1 loop {|x| x = 0; break} px #=> warning: multiple values for a block parameter #0 Ruby 1.9.1 x = 1 loop {|x| x = 0; break} px #=> 1
  • 20. 文法の変更(2/2) • Post Argument Ruby 1.8.6 def foo(front, *temp, last) end #=> Syntax Error Ruby 1.9.1 def foo(front, *temp, last) end #=> OK • splat(配列展開) Ruby 1.8.6 puts(*ary1, *ary2) #=> Syntax Error Ruby 1.9.1 puts(*ary1, *ary2) #=> OK
  • 22. 省メモリ化 • 省メモリ化 – 標準クラス String, Array, Hash など – 性能よりもメモリ使用量削減に力を • GC の改良
  • 23. Ruby 1.9.1 まとめ • いろいろ便利な機能が追加された • 性能向上が期待できる
  • 24. Ruby 1.8.6 → 1.8.7 • Ruby 1.9 からのバックポート多数 – Enumerator – Array の拡張 – tap – その他新規メソッドの追加
  • 25. Windows で Ruby をコンパイル • 環境 – OS: Windows XP SP3 & Windows Vista SP1 – Compiler: Visual C++ 2008 Express Edition(無料) • Ruby – Ruby 1.8.6 p368 – Ruby 1.8.7 p160 – Ruby 1.9.1 p0
  • 26. Ruby のコンパイル • 公式からソースを ダウンロード, 解凍 • VC++ のコマンドプロンプトを起動 • ソースフォルダに移動して C:ruby-1.8.7-p160>cd win32 C:ruby-1.8.7-p160win32>configure.bat C:ruby-1.8.7-p160win32>nmake C:ruby-1.8.7-p160win32>nmake DESTDIR=C:/Ruby install • Ruby 1.9.1 は C:ruby-1.9.1-p0>cd win32 C:ruby-1.9.1-p0win32>configure.bat --prefix=C:/Ruby C:ruby-1.9.1-p0win32>nmake C:ruby-1.9.1-p0win32>nmake install
  • 27. 拡張ライブラリのコンパイル • 拡張ライブラリの Win32 用 バイナリを ダウンロード or コンパイル – 必要な物はバイナリ(DLL ファイル)と ヘッダファイルと *.lib ファイル • ext フォルダ内の目的の拡張ライブラリ フォルダに移動 • extconf.rb を使って Makefile を作成 • *.so ファイルが出来れば OK • ruby.exe のあるフォルダに DLL ファイルをコピー
  • 28. 例:zlib のコンパイル • zlib-1.1.4-1 バイナリ作成 C:zlib-1.1.4-1>cd win32 C:zlib-1.1.4-1>nmake C:zlib-1.1.4-1>mt –manifest zlib.dll.manifest –outputsource:zlib.dll;2 C:zlib-1.1.4-1>copy zlib.dll C:/Ruby/bin • Ruby にインストール C:ruby-1.8.7-p160>cd extzlib C:ruby-1.8.7-p160extzlib>ruby extconf.rb --with-zlib-include=C:zlib- 1.1.4-1include --with-zlib-lib=C:zlib-1.1.4-1lib C:ruby-1.8.7-p160win32>nmake C:ruby-1.8.7-p160win32>nmake install ※ ruby にパスが通ってないと extconf.rb は実行できない
  • 29. 詰みポイント • openssl – extconf.rb が吐いた Makefile の中にある CFLAGS のパラメータを変更しないとエラー CFLAGS = -MD -O2b2xty- CFLAGS = -MD -DWIN32_LEAN_AND_MEAN -O2b2xty- • zlib 1.2.3 – Windows 版では謎の挙動(バグ?)を するため gem でエラーが起きる – 回避するためにはパッチを当てる必要がある • Bug#888 [Ruby-core:20576] – zlib 1.1.4-1 では gem 側に回避する措置がとられてい るのでエラーは起きない
  • 30. その他の mswin32 版 Ruby • One-Click Installer – Ruby 1.8.6 – インストーラ付き • InstantRails – Ruby 1.8.6 with Rails – Apache – MySQL • ActiveScriptRuby – Ruby 1.8.7 – ActiveScript で Ruby が使える – その他必要なもの一通りセット • Rumix – Ruby 1.8.7 – インストーラ付き • Ruby-mswin32 (ja) – Ruby 1.9.1 までの各種バージョン – 手動インストール
  • 31. 今後の予定 • Ruby on Rails or Merb を使って Web 開発