Menu

gitpiper

Ruby 2.1 Cheat Sheet in March 2024

Last Updated: 24 March 2024

README.md

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


338+ more cheat sheets for you in March 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️