Last active
March 29, 2016 23:38
-
-
Save spanuska/b6d3c73050dbdc5d8951 to your computer and use it in GitHub Desktop.
Book with default arguments hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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