mirror of
https://github.com/onkelbeh/cheatsheets.git
synced 2025-06-15 22:57:33 +02:00
495 B
495 B
title | category |
---|---|
Ruby 2.1 | Ruby |
Named arguments with defaults
# length is required
def pad(num, length:, char: "0")
num.to_s.rjust(length, char)
end
pad(42, length: 6) #=> "000042"
pad(42) #=> #<ArgumentError: missing keyword: length>
Module.prepend
prepend(Module.new do
define_method ...
end)