OSDN Git Service

Regular updates
[twpd/master.git] / ruby21.md
1 ---
2 title: Ruby 2.1
3 category: Ruby
4 ---
5
6 ### Named arguments with defaults
7
8     # length is required
9     def pad(num, length:, char: "0")
10       num.to_s.rjust(length, char)
11     end
12
13     pad(42, length: 6)   #=> "000042"
14     pad(42)              #=> #<ArgumentError: missing keyword: length>
15
16 ### Module.prepend
17
18     prepend(Module.new do
19       define_method ...
20     end)
21
22 ### References
23
24  * http://globaldev.co.uk/2013/03/ruby-2-0-0-in-detail
25  * http://globaldev.co.uk/2014/05/ruby-2-1-in-detail