1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-16 07:07:37 +02:00
cheatsheets/ruby21.md
2020-07-03 22:47:47 +10:00

612 B

title category layout tags intro
Ruby 2.1 Ruby 2017/sheet
Archived
Quick reference to the [new features in Ruby 2.1](https://www.ruby-lang.org/).

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
)

References