Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Last active August 29, 2015 14:04
Show Gist options
  • Save jgaskins/7f8d020302fc1ca0f88e to your computer and use it in GitHub Desktop.
Save jgaskins/7f8d020302fc1ca0f88e to your computer and use it in GitHub Desktop.
Default values
class Foo
def initialize: (attributes={}) ->
# Set default day to Monday
# This broke for Sunday (attributes.day == 0)
@day = attributes.day || 1
# How I ended up doing it
@day = if attributes.hasOwnProperty('day') then attributes.day else 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment