本文簡要介紹ruby語言中 ERB::DefMethod模塊
的用法。
用於將 eRuby 腳本定義為實例方法的實用程序模塊。
示例
例子.rhtml:
<% for item in @items %> <b><%= item %></b> <% end %>
例子.rb:
require 'erb'
class MyClass
extend ERB::DefMethod
def_erb_method('render()', 'example.rhtml')
def initialize(items)
@items = items
end
end
print MyClass.new([10,20,30]).render()
結果:
<b>10</b> <b>20</b> <b>30</b>
相關用法
- Ruby Deflate.new用法及代碼示例
- Ruby Deflate.deflate用法及代碼示例
- Ruby DependencyState.pop_possibility_state用法及代碼示例
- Ruby DependencyGraph.==用法及代碼示例
- Ruby DependencyGraph.vertices用法及代碼示例
- Ruby Delegator類用法及代碼示例
- Ruby Deprecate模塊用法及代碼示例
- Ruby DependencyGraph.tsort用法及代碼示例
- Ruby Date.valid_civil?用法及代碼示例
- Ruby DateTime jisx0301()用法及代碼示例
- Ruby Date cwday()用法及代碼示例
- Ruby Date ctime()用法及代碼示例
- Ruby Date.gregorian?用法及代碼示例
- Ruby DRb.regist_server用法及代碼示例
- Ruby DH.public_key用法及代碼示例
- Ruby Date asctime()用法及代碼示例
- Ruby DateTime類用法及代碼示例
- Ruby DateTime.hour用法及代碼示例
- Ruby DateTime.jd用法及代碼示例
- Ruby DateTime.zone用法及代碼示例
- Ruby DateTime ordinal()用法及代碼示例
- Ruby DateTime.second用法及代碼示例
- Ruby Date.strftime用法及代碼示例
- Ruby Digest.update用法及代碼示例
- Ruby DSA.export用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 DefMethod模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。