Skip to content

Instantly share code, notes, and snippets.

@spanuska
Last active March 29, 2016 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spanuska/b6d3c73050dbdc5d8951 to your computer and use it in GitHub Desktop.
Save spanuska/b6d3c73050dbdc5d8951 to your computer and use it in GitHub Desktop.
Book with default arguments hash
class Book
....
def initialize(args)
args = defaults.merge(args) # If you're using Ruby <2.0, this is the way to go.
@title = args[:title]
@author = args[:author]
end
def defaults
{title: "Unknown", author: "Unknown"}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment