Skip to content

Instantly share code, notes, and snippets.

@mahm
Last active August 29, 2015 14:09
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 mahm/20580ccee12af9e04664 to your computer and use it in GitHub Desktop.
Save mahm/20580ccee12af9e04664 to your computer and use it in GitHub Desktop.
2014/11/12のブログ記事のサンプルコード
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>
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
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>
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])
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])
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