![Page 1: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/1.jpg)
erbを偲んで愚痴と謝罪
![Page 2: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/2.jpg)
重要なことを先に
• 先に
![Page 3: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/3.jpg)
重要
• 初刷まだ買えます
dRubyによる
関 将俊 著
分散・Webプログラミング
![Page 4: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/4.jpg)
Who is translating it?
• 英語版はまだ買えません
![Page 5: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/5.jpg)
私について
• 今日はtoRubyの方から
• 西那須野公民館まで約100km
• toRuby7月増刊号は7/12(土)!
![Page 6: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/6.jpg)
<%=h .... %>
• 代表作• Erubisの中の人も絶賛
![Page 7: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/7.jpg)
今日はちょっと愚痴りたい
• MVCわかんない
• 以前のトークスをリサイクル• 1.8.7での失敗に関する言い訳
![Page 8: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/8.jpg)
オブジェクト倶楽部2006夏
![Page 9: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/9.jpg)
ERB Revealed.
Recycled
![Page 10: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/10.jpg)
私は違うがそうらしい
世界中のプログラマはWebベース帳票システムを書いてビジネスを加速させている
らしい
![Page 11: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/11.jpg)
MVC復興期
Webアプリに普通の人が流入
フレームワークをMVCで解説
ふつうの人から普通の人へ
![Page 12: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/12.jpg)
MVCなモデル
• 原理主義者にとってはSmalltalkのアレ
• 広くとらえるならそこら中に在るもの• オブジェクト群の相対的な関係
![Page 13: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/13.jpg)
普通のView
Model-Controllerよくわからん
View想像しやすい
Viewとは
![Page 14: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/14.jpg)
Viewとは
テンプレートのことであるらしい
ERB / JSP / ASP
![Page 15: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/15.jpg)
テンプレートこそ全て
PH(ry
![Page 16: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/16.jpg)
分業はすばらしい
デザイナとプログラマに分けよ。
え?Agile方面としてはどうよ?
連絡コスト高いし
てゆかそううまく切れるの?
![Page 17: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/17.jpg)
えー
本当?
![Page 18: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/18.jpg)
協業すれば
• いいのにね
![Page 19: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/19.jpg)
GUI
GUIとWeb UIとなにか違うの?
GUIの黒歴史に学ぶ
忘れてたけど私はGUI15年
![Page 20: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/20.jpg)
コードだけでやる
はじまり
座標とか色とか書くのめんどう
いつものコードとは異質なモノ
![Page 21: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/21.jpg)
やってられない
部品の記述をコードの外へ
書きやすい記法・配置
テンプレートと言い換えてみる
![Page 22: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/22.jpg)
コード+テンプレート
MacOS Toolbox + RSRC
Motif + UIL
X11/Xt + X resource
Cocoa + IB
![Page 23: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/23.jpg)
二つの世界
コードとテンプレート
お互いを意識して繋いでる
単体では存在できない
htmlとcssもちょっと似てる
![Page 24: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/24.jpg)
Viewとは
View Objectだよ
実行環境+テンプレート
![Page 25: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/25.jpg)
実行環境+テンプレート
ベンハムのコマ
うまいことをいう
> gotoken
![Page 26: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/26.jpg)
書きやすいから
そう書くのが楽だから使う
分業するためじゃない
![Page 27: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/27.jpg)
ERBとは
Rubyを文書に埋め込む
文書が主
html専用じゃない
![Page 28: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/28.jpg)
Hello, World.
puts "Hello, World."
![Page 29: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/29.jpg)
Hello, World.
Hello, World.
![Page 30: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/30.jpg)
99 Bottles of Beer
• 予習してきましたか?
• マザーグースの詩を出力する遊び
![Page 31: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/31.jpg)
99 Bottles of Beer
99 bottles of beer on the wall, 99 bottles of beer.Take one down and pass it around, 98 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer.Take one down and pass it around, 97 bottles of beer on the wall.
97 bottles of beer on the wall, 97 bottles of beer.Take one down and pass it around, 96 bottles of beer on the wall.
...
2 bottles of beer on the wall, 2 bottles of beer.Take one down and pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.Go to the store and buy some more, 99 bottles of beer on the wall.
![Page 32: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/32.jpg)
99 Bottles of Beer
puts "99 bottles of beer on the wall, 99 bottles of beer."98.downto(2) do |i| puts "Take one down and pass it around, #{i} bottles of beer on the wall." puts puts "#{i} bottles of beer on the wall, #{i} bottles of beer."endputs "Take one down and pass it around, 1 bottle of beer on the wall."putsputs "1 bottle of beer on the wall, 1 bottle of beer."puts "Go to the store and buy some more, 99 bottles of beer on the wall."
![Page 33: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/33.jpg)
99 Bottles of Beer
99 bottles of beer on the wall, 99 bottles of beer.<%- 98.downto(2) do |i| -%>Take one down and pass it around, <%= i %> bottles of beer on the wall.
<%= i %> bottles of beer on the wall, <%= i %> bottles of beer.<%- end -%>Take one down and pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.Go to the store and buy some more, 99 bottles of beer on the wall.
![Page 34: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/34.jpg)
<%- -%>
• はじめて使ったけど99bottlesにはいいね
• こんな仕様忘れてた• Rails偉い
![Page 35: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/35.jpg)
ERB way
Rubyを文書に埋め込み
ERBをアプリに埋め込む
再びコードが主
テンプレートだけで使わない
使えなくもないけど
![Page 36: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/36.jpg)
99 Bottles of Beerrequire 'erb'
S = <<EOS<%- beer = Beer[size] -%><%=beer%> on the wall, <%=beer%>.<%- while beer = beer.take -%>Take one down and pass it around, <%=beer%> on the wall.
<%=beer%> on the wall, <%=beer%>.<%- end -%>Go to the store and buy some more, <%=Beer[size]%> on the wall.EOS
class Beer def initialize(n); @n = n; end def to_s; "#{@n} bottles of beer"; end def take; Beer[@n-1]; end class One < Beer def to_s; "1 bottle of beer"; end end def self.[](n) return nil if n <= 0 (n == 1) ? One.new(1) : Beer.new(n) end def self.sing(size) ERB.new(S, nil, '-').result(binding) endend
puts Beer.sing(99)
![Page 37: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/37.jpg)
require 'erb'
S = <<EOS<%- beer = Beer[size] -%><%=beer%> on the wall, <%=beer%>.<%- while beer = beer.take -%>Take one down and pass it around, <%=beer%> on the wall.
<%=beer%> on the wall, <%=beer%>.<%-end -%>Go to the store and buy some more, <%=Beer[size]%> on the wall.EOS
class Beer def initialize(n); @n = n; end def to_s; "#{@n} bottles of beer"; end def take; Beer[@n-1]; end class One < Beer def to_s; "1 bottle of beer"; end end def self.[](n) return nil if n <= 0 (n == 1) ? One.new(1) : Beer.new(n) end def self.sing(size) ERB.new(S, nil, '-').result(binding) endend
puts Beer.sing(99)
<%- beer = Beer[size] -%><%=beer%> on the wall, <%=beer%>.<%- while beer = beer.take -%>Take one down and pass it around, <%=beer%> on the wall.
<%=beer%> on the wall, <%=beer%>.<%- end -%>Go to the store and buy some more, <%=Beer[size]%> on the wall.
![Page 38: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/38.jpg)
method
def self.sing(size) ERB.new(S, nil, '-').result(binding) end
ERB.new(S, nil, '-').def_method(self, “self.sing(size)”)
![Page 39: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/39.jpg)
ERB way, more
HTMLでなくHTML片を返す
壊れたHTMLを許す
メソッド化でERBの入れ子
レンダリングの最後だけじゃない
![Page 40: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/40.jpg)
ERB on Rails
フレームワークの一部として
Rails様々
dRubyも使ってる
![Page 41: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/41.jpg)
tDiary
BR世代のキラーアプリ
ERB wayを具現
![Page 42: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/42.jpg)
ただただし/arton共著
• ジュンク堂RubyKaigi支店
![Page 43: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/43.jpg)
RWiki, Div&Tofu
BR世代の自画自賛系
さっぱりブームはこない
![Page 44: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/44.jpg)
もう一度
Viewはテンプレートじゃない
View Objectだよ
実行環境とテンプレート
ERB way
![Page 45: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/45.jpg)
重要
まだ初刷買えます!
dRubyによる
関 将俊 著
分散・Webプログラミング
![Page 46: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/46.jpg)
One more thing...
![Page 47: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/47.jpg)
言いにくいことは最後に
• [ruby-core:17033] Ruby 1.8.7: ERB is broken
• ごめんなさい• strscanがない状況でのテスト抜け‥
![Page 48: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/48.jpg)
言い訳
• eRuby→Ruby変換速度改善の失敗
• RK07のid: kwatchさんの発表に釣られた
![Page 49: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/49.jpg)
なにをしたか• 従来は行ごとに分けて処理してた• トークンに出会うまでまとめて扱う• 複数行を一度に処理できた場合に効く• あとは飽きちゃった...
• てゆか細かい工夫とか苦手...
![Page 50: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/50.jpg)
実行時間
• eRuby→Rubyへの変換にかかる時間
• そのRubyスクリプトの実行時間
• メソッド化した場合の実行時間
![Page 51: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/51.jpg)
99 Bottles of Beerrequire 'benchmark'require 'erb'require 'yaml'
script = File.read('erubybench.rhtml')context = YAML.load_file('erubybench.yaml')list = context['list']
count = 1000Benchmark.bm(20) do |x| x.report('ERB.new') { count.times { ERB.new(script) } }
erb = ERB.new(script) x.report('erb.result') { count.times { erb.result } }
erb.def_method(Kernel, 'erb_bench(list)') x.report('def_method') { count.times { erb_bench(list) } }end
1000回やるよ
メソッド化した処理にかかる時間
![Page 52: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/52.jpg)
elapsed time
ruby-1.8.6 ruby-1.8.7
ERB.new.result 4.69 2.46
(ERB.new) 3.16 1.49
(erb.result) 1.53 0.97
def_method 0.83 0.62
![Page 53: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/53.jpg)
elapsed time
ERB.new.result
(ERB.new)
(erb.result)
def_method
1.8.6 1.8.7
45%off!
87%off!
![Page 54: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/54.jpg)
速度
• ERB.newだと2倍くらい
• resultやdef_methodも多少
• いつでもメソッド化すべき
![Page 55: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/55.jpg)
Railsは速くなるか?
• “Ruby on Rails ではたしかに View 層に時間がかかりますが、View 層が遅い原因は ERB ではなくヘルパー関数だったわけです。” - RubyistMagazine0021
• 釣られた!?
![Page 56: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/56.jpg)
てゆかこれって
• 定数な行が連続するほど旧版が遅い?
• ということは...
![Page 57: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/57.jpg)
テストデータの工夫
• 変換されない行をたくさん書こう!
• 任意の改善比が出せるぞ
![Page 58: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/58.jpg)
99 Bottles of Beer99 bottles of beer on the wall, 99 bottles of beer.Take one down and pass it around, 98 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer.Take one down and pass it around, 97 bottles of beer on the wall.
97 bottles of beer on the wall, 97 bottles of beer.Take one down and pass it around, 96 bottles of beer on the wall.
96 bottles of beer on the wall, 96 bottles of beer.Take one down and pass it around, 95 bottles of beer on the wall.
95 bottles of beer on the wall, 95 bottles of beer.Take one down and pass it around, 94 bottles of beer on the wall.
94 bottles of beer on the wall, 94 bottles of beer.Take one down and pass it around, 93 bottles of beer on the wall.
93 bottles of beer on the wall, 93 bottles of beer.Take one down and pass it around, 92 bottles of beer on the wall.
92 bottles of beer on the wall, 92 bottles of beer.Take one down and pass it around, 91 bottles of beer on the wall.
![Page 59: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/59.jpg)
92 bottles of beer on the wall, 92 bottles of beer.Take one down and pass it around, 91 bottles of beer on the wall.
91 bottles of beer on the wall, 91 bottles of beer.Take one down and pass it around, 90 bottles of beer on the wall.
90 bottles of beer on the wall, 90 bottles of beer.Take one down and pass it around, 89 bottles of beer on the wall.
89 bottles of beer on the wall, 89 bottles of beer.Take one down and pass it around, 88 bottles of beer on the wall.
88 bottles of beer on the wall, 88 bottles of beer.Take one down and pass it around, 87 bottles of beer on the wall.
87 bottles of beer on the wall, 87 bottles of beer.Take one down and pass it around, 86 bottles of beer on the wall.
86 bottles of beer on the wall, 86 bottles of beer.Take one down and pass it around, 85 bottles of beer on the wall.
85 bottles of beer on the wall, 85 bottles of beer.Take one down and pass it around, 84 bottles of beer on the wall.
84 bottles of beer on the wall, 84 bottles of beer.Take one down and pass it around, 83 bottles of beer on the wall.
83 bottles of beer on the wall, 83 bottles of beer.Take one down and pass it around, 82 bottles of beer on the wall.
![Page 60: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/60.jpg)
82 bottles of beer on the wall, 82 bottles of beer.Take one down and pass it around, 81 bottles of beer on the wall.
81 bottles of beer on the wall, 81 bottles of beer.Take one down and pass it around, 80 bottles of beer on the wall.
80 bottles of beer on the wall, 80 bottles of beer.Take one down and pass it around, 79 bottles of beer on the wall.
79 bottles of beer on the wall, 79 bottles of beer.Take one down and pass it around, 78 bottles of beer on the wall.
78 bottles of beer on the wall, 78 bottles of beer.Take one down and pass it around, 77 bottles of beer on the wall.
77 bottles of beer on the wall, 77 bottles of beer.Take one down and pass it around, 76 bottles of beer on the wall.
76 bottles of beer on the wall, 76 bottles of beer.Take one down and pass it around, 75 bottles of beer on the wall.
75 bottles of beer on the wall, 75 bottles of beer.Take one down and pass it around, 74 bottles of beer on the wall.
74 bottles of beer on the wall, 74 bottles of beer.Take one down and pass it around, 73 bottles of beer on the wall.
73 bottles of beer on the wall, 73 bottles of beer.Take one down and pass it around, 72 bottles of beer on the wall.
![Page 61: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/61.jpg)
72 bottles of beer on the wall, 72 bottles of beer.Take one down and pass it around, 71 bottles of beer on the wall.
71 bottles of beer on the wall, 71 bottles of beer.Take one down and pass it around, 70 bottles of beer on the wall.
70 bottles of beer on the wall, 70 bottles of beer.Take one down and pass it around, 69 bottles of beer on the wall.
69 bottles of beer on the wall, 69 bottles of beer.Take one down and pass it around, 68 bottles of beer on the wall.
68 bottles of beer on the wall, 68 bottles of beer.Take one down and pass it around, 67 bottles of beer on the wall.
67 bottles of beer on the wall, 67 bottles of beer.Take one down and pass it around, 66 bottles of beer on the wall.
66 bottles of beer on the wall, 66 bottles of beer.Take one down and pass it around, 65 bottles of beer on the wall.
65 bottles of beer on the wall, 65 bottles of beer.Take one down and pass it around, 64 bottles of beer on the wall.
64 bottles of beer on the wall, 64 bottles of beer.Take one down and pass it around, 63 bottles of beer on the wall.
63 bottles of beer on the wall, 63 bottles of beer.Take one down and pass it around, 62 bottles of beer on the wall.
![Page 62: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/62.jpg)
62 bottles of beer on the wall, 62 bottles of beer.Take one down and pass it around, 61 bottles of beer on the wall.
61 bottles of beer on the wall, 61 bottles of beer.Take one down and pass it around, 60 bottles of beer on the wall.
60 bottles of beer on the wall, 60 bottles of beer.Take one down and pass it around, 59 bottles of beer on the wall.
59 bottles of beer on the wall, 59 bottles of beer.Take one down and pass it around, 58 bottles of beer on the wall.
58 bottles of beer on the wall, 58 bottles of beer.Take one down and pass it around, 57 bottles of beer on the wall.
57 bottles of beer on the wall, 57 bottles of beer.Take one down and pass it around, 56 bottles of beer on the wall.
56 bottles of beer on the wall, 56 bottles of beer.Take one down and pass it around, 55 bottles of beer on the wall.
55 bottles of beer on the wall, 55 bottles of beer.Take one down and pass it around, 54 bottles of beer on the wall.
54 bottles of beer on the wall, 54 bottles of beer.Take one down and pass it around, 53 bottles of beer on the wall.
53 bottles of beer on the wall, 53 bottles of beer.Take one down and pass it around, 52 bottles of beer on the wall.
![Page 63: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/63.jpg)
52 bottles of beer on the wall, 52 bottles of beer.Take one down and pass it around, 51 bottles of beer on the wall.
51 bottles of beer on the wall, 51 bottles of beer.Take one down and pass it around, 50 bottles of beer on the wall.
50 bottles of beer on the wall, 50 bottles of beer.Take one down and pass it around, 49 bottles of beer on the wall.
49 bottles of beer on the wall, 49 bottles of beer.Take one down and pass it around, 48 bottles of beer on the wall.
48 bottles of beer on the wall, 48 bottles of beer.Take one down and pass it around, 47 bottles of beer on the wall.
47 bottles of beer on the wall, 47 bottles of beer.Take one down and pass it around, 46 bottles of beer on the wall.
46 bottles of beer on the wall, 46 bottles of beer.Take one down and pass it around, 45 bottles of beer on the wall.
45 bottles of beer on the wall, 45 bottles of beer.Take one down and pass it around, 44 bottles of beer on the wall.
44 bottles of beer on the wall, 44 bottles of beer.Take one down and pass it around, 43 bottles of beer on the wall.
43 bottles of beer on the wall, 43 bottles of beer.Take one down and pass it around, 42 bottles of beer on the wall.
![Page 64: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/64.jpg)
42 bottles of beer on the wall, 42 bottles of beer.Take one down and pass it around, 41 bottles of beer on the wall.
41 bottles of beer on the wall, 41 bottles of beer.Take one down and pass it around, 40 bottles of beer on the wall.
40 bottles of beer on the wall, 40 bottles of beer.Take one down and pass it around, 39 bottles of beer on the wall.
39 bottles of beer on the wall, 39 bottles of beer.Take one down and pass it around, 38 bottles of beer on the wall.
38 bottles of beer on the wall, 38 bottles of beer.Take one down and pass it around, 37 bottles of beer on the wall.
37 bottles of beer on the wall, 37 bottles of beer.Take one down and pass it around, 36 bottles of beer on the wall.
36 bottles of beer on the wall, 36 bottles of beer.Take one down and pass it around, 35 bottles of beer on the wall.
35 bottles of beer on the wall, 35 bottles of beer.Take one down and pass it around, 34 bottles of beer on the wall.
34 bottles of beer on the wall, 34 bottles of beer.Take one down and pass it around, 33 bottles of beer on the wall.
33 bottles of beer on the wall, 33 bottles of beer.Take one down and pass it around, 32 bottles of beer on the wall.
![Page 65: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/65.jpg)
32 bottles of beer on the wall, 32 bottles of beer.Take one down and pass it around, 31 bottles of beer on the wall.
31 bottles of beer on the wall, 31 bottles of beer.Take one down and pass it around, 30 bottles of beer on the wall.
30 bottles of beer on the wall, 30 bottles of beer.Take one down and pass it around, 29 bottles of beer on the wall.
29 bottles of beer on the wall, 29 bottles of beer.Take one down and pass it around, 28 bottles of beer on the wall.
28 bottles of beer on the wall, 28 bottles of beer.Take one down and pass it around, 27 bottles of beer on the wall.
27 bottles of beer on the wall, 27 bottles of beer.Take one down and pass it around, 26 bottles of beer on the wall.
26 bottles of beer on the wall, 26 bottles of beer.Take one down and pass it around, 25 bottles of beer on the wall.
25 bottles of beer on the wall, 25 bottles of beer.Take one down and pass it around, 24 bottles of beer on the wall.
24 bottles of beer on the wall, 24 bottles of beer.Take one down and pass it around, 23 bottles of beer on the wall.
23 bottles of beer on the wall, 23 bottles of beer.Take one down and pass it around, 22 bottles of beer on the wall.
![Page 66: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/66.jpg)
22 bottles of beer on the wall, 22 bottles of beer.Take one down and pass it around, 21 bottles of beer on the wall.
21 bottles of beer on the wall, 21 bottles of beer.Take one down and pass it around, 20 bottles of beer on the wall.
20 bottles of beer on the wall, 20 bottles of beer.Take one down and pass it around, 19 bottles of beer on the wall.
19 bottles of beer on the wall, 19 bottles of beer.Take one down and pass it around, 18 bottles of beer on the wall.
18 bottles of beer on the wall, 18 bottles of beer.Take one down and pass it around, 17 bottles of beer on the wall.
17 bottles of beer on the wall, 17 bottles of beer.Take one down and pass it around, 16 bottles of beer on the wall.
16 bottles of beer on the wall, 16 bottles of beer.Take one down and pass it around, 15 bottles of beer on the wall.
15 bottles of beer on the wall, 15 bottles of beer.Take one down and pass it around, 14 bottles of beer on the wall.
14 bottles of beer on the wall, 14 bottles of beer.Take one down and pass it around, 13 bottles of beer on the wall.
13 bottles of beer on the wall, 13 bottles of beer.Take one down and pass it around, 12 bottles of beer on the wall.
![Page 67: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/67.jpg)
12 bottles of beer on the wall, 12 bottles of beer.Take one down and pass it around, 11 bottles of beer on the wall.
11 bottles of beer on the wall, 11 bottles of beer.Take one down and pass it around, 10 bottles of beer on the wall.
10 bottles of beer on the wall, 10 bottles of beer.Take one down and pass it around, 9 bottles of beer on the wall.
9 bottles of beer on the wall, 9 bottles of beer.Take one down and pass it around, 8 bottles of beer on the wall.
8 bottles of beer on the wall, 8 bottles of beer.Take one down and pass it around, 7 bottles of beer on the wall.
7 bottles of beer on the wall, 7 bottles of beer.Take one down and pass it around, 6 bottles of beer on the wall.
6 bottles of beer on the wall, 6 bottles of beer.Take one down and pass it around, 5 bottles of beer on the wall.
5 bottles of beer on the wall, 5 bottles of beer.Take one down and pass it around, 4 bottles of beer on the wall.
4 bottles of beer on the wall, 4 bottles of beer.Take one down and pass it around, 3 bottles of beer on the wall.
3 bottles of beer on the wall, 3 bottles of beer.Take one down and pass it around, 2 bottles of beer on the wall.
![Page 68: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/68.jpg)
Go to the store and buy
2 bottles of beer on the wall, 2 bottles of beer.Take one down and pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.Go to the store and buy some more, 99 bottles of beer on the wall.
![Page 69: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/69.jpg)
elapsed time
ERB.new.result
(ERB.new)
(erb.result)
def_method
1.8.6 1.8.7
65%off!
99%off!
![Page 70: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/70.jpg)
knuさんごめんなさい
• そんなことをしているうちにstrscanがない環境でのテストを忘れました‥
• [ruby-core:17033] Ruby 1.8.7: ERB is broken
![Page 71: 愚痴と謝罪 seki@drubyModel-Controllerよくわからん View想像しやすい Viewとは Viewとは テンプレートのことであるらしい ERB / JSP / ASP ... • “Ruby](https://reader035.vdocuments.us/reader035/viewer/2022063022/5fe7a68b1686b5136e6c8c75/html5/thumbnails/71.jpg)
まとめ
• 代表作は<%=h %>
• ViewはView Object
• スルー力重要