-
-
Save katoy/6886252 to your computer and use it in GitHub Desktop.
erb の利用例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'erb' | |
require 'time' | |
def make_body(template, name, time, params) | |
erb = ERB.new(template) | |
result = erb.result(binding) | |
end | |
puts make_body(File.read("body.txt"), "kato", Time.now + 60*60*24, {名前: "加藤", 時間: Time.new}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test | |
テスト | |
<%= params[:時間].strftime("%Y-%m-%d") %> | |
<%= params[:名前] %> | |
<%= name %> | |
<%= time.strftime("%Y-%m-%d") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby 1.rb | |
test | |
テスト | |
2013-10-09 | |
加藤 | |
kato | |
2013-10-10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment