Skip to content

Files

Latest commit

511de90 · Apr 3, 2024

History

History
36 lines (29 loc) · 593 Bytes

ruby21.md

File metadata and controls

36 lines (29 loc) · 593 Bytes
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