Skip to content

Instantly share code, notes, and snippets.

@clamstew
Forked from taylor-smith/gist:6704904
Created September 25, 2013 19:46
Show Gist options
  • Save clamstew/6705022 to your computer and use it in GitHub Desktop.
Save clamstew/6705022 to your computer and use it in GitHub Desktop.
def initialize (args={:event_time, :deadline, :event_name, :event_location, :minimum_attendees, :maximum_attendees, :creator_name, :phone, :email, :invitees})
@required = args.fetch(:event_time, :deadline, :minimum_attendees) # .fetch will throw an error if key doesn't exist in Hash
@optional = args[:creator, :event_name, :event_location, :attendees, :maximum_attendees] # simple access returns nil if key isn't set--no exception raised
end
@clamstew
Copy link
Author

Example of putting optional parameters in the initialize method of a class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment