1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-10-15 23:18:52 +02:00
cheatsheets/ruby21.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

593 B

title, category, tags, intro
title category tags intro
Ruby 2.1 Ruby
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