Created
February 29, 2012 05:25
-
-
Save ukitazume/1938147 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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