Skip to content

Instantly share code, notes, and snippets.

@katoy
Created October 8, 2013 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katoy/6886252 to your computer and use it in GitHub Desktop.
Save katoy/6886252 to your computer and use it in GitHub Desktop.
erb の利用例
# -*- 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})
test
テスト
<%= params[:時間].strftime("%Y-%m-%d") %>
<%= params[:名前] %>
<%= name %>
<%= time.strftime("%Y-%m-%d") %>
$ 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