Last active
August 29, 2015 14:09
-
-
Save mahm/20580ccee12af9e04664 to your computer and use it in GitHub Desktop.
2014/11/12のブログ記事のサンプルコード
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
class Post | |
def initialize(title, body) | |
@title, @body = title, body | |
end | |
def render | |
<<-EOS | |
<article> | |
<h1>#{@title}</h1> | |
<p>#{@body}</p> | |
</article> | |
EOS | |
end | |
end | |
post = Post.new('タイトル', '記事の内容') | |
puts post.render | |
# => | |
# <article> | |
# <h1>タイトル</h1> | |
# 記事の内容 | |
# </article> |
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
class Post | |
def initialize(title, body) | |
@title, @body = title, body | |
end | |
def render | |
<<-EOS | |
<article> | |
<h1>#{@title}</h1> | |
<p>#{@body}</p> | |
</article> | |
EOS | |
end | |
def self.find(filename) | |
path = File.join(File.dirname(__FILE__), filename) | |
title, body = File.read(path).split("\n", 2).map(&:strip) | |
Post.new(title, body) | |
end | |
end | |
post = Post.find('foo.txt') | |
puts post.render |
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
class Post | |
def self.render(title, body) | |
<<-EOS | |
<article> | |
<h1>#{title}</h1> | |
<p>#{body}</p> | |
</article> | |
EOS | |
end | |
end | |
puts Post.render('タイトル', '記事の内容') | |
# => | |
# <article> | |
# <h1>タイトル</h1> | |
# 記事の内容 | |
# </article> |
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
class Post | |
def self.render(title, body) | |
<<-EOS | |
<article> | |
<h1>#{title}</h1> | |
<p>#{body}</p> | |
</article> | |
EOS | |
end | |
def self.find(filename) | |
path = File.join(File.dirname(__FILE__), filename) | |
title, body = File.read(path).split("\n", 2).map(&:strip) | |
{ title: titile, body: body } | |
end | |
end | |
post_hash = Post.find('foo.txt') | |
Post.render(post_hash[:title], post_hash[:body]) |
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
class Post | |
def self.render(title, keyword, description, category, body) | |
<<-EOS | |
<article> | |
<h1>#{title}</h1> | |
<p>#{keyword} #{description} #{category}</p> | |
<p>#{body}</p> | |
</article> | |
EOS | |
end | |
def self.find(filename) | |
path = File.join(File.dirname(__FILE__), filename) | |
title, keyword, description, category, body = File.read(path).split("\n", 5).map(&:strip) | |
{ title: titile, keyword: keyword, description: description, category: category, body: body } | |
end | |
end | |
post_hash = Post.find('foo.txt') | |
Post.render(post_hash[:title], post_hash[:keyword], post_hash[:description], post_hash[:category], post_hash[:body]) |
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
class Post | |
def initialize(title, keyword, description, category, body) | |
@title = title | |
@keyword = keyword | |
@description = description | |
@category = category | |
@body = body | |
end | |
def render | |
<<-EOS | |
<article> | |
<h1>#{@title}</h1> | |
<p>#{@keyword} #{@description} #{@category}</p> | |
<p>#{@body}</p> | |
</article> | |
EOS | |
end | |
def self.find(filename) | |
path = File.join(File.dirname(__FILE__), filename) | |
title, keyword, description, category, body = File.read(path).split("\n", 5).map(&:strip) | |
Post.new(title, keyword, description, category, body) | |
end | |
end | |
post = Post.find('foo.txt') | |
post.render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment