Skip to content

Instantly share code, notes, and snippets.

@ukitazume
Created February 29, 2012 05:25
Show Gist options
  • Select an option

  • Save ukitazume/1938147 to your computer and use it in GitHub Desktop.

Select an option

Save ukitazume/1938147 to your computer and use it in GitHub Desktop.
def press(op)
title = op[:title] || 'no title'
body = op[:body] || 'none'
print %Q{
Title: #{title}
----------------
#{body}
}
end
# 唯一のHash引数を名前付きの引数のように使う
press title: "Today's topic", body: "It's snow today at Tokyo."
def complex_press(op, ps)
press(op)
print %Q{
ps:
#{ps}
}
end
# この場合は、{}で囲む必要がある
complex_press(
{title: "Today's topic", body: "It's snow today at Tokyo."},
"It's too cold")
def ps_press(ps, op)
press(op)
print %Q{
ps:
#{ps}
}
end
# 一番後ろの場合は、{}で囲まなくていい
ps_press("It's too cold", title: "Today's topic", body: "It's snow today at Tokyo.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment