Skip to content

Instantly share code, notes, and snippets.

@shime
Created April 8, 2012 19:10
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 shime/2339328 to your computer and use it in GitHub Desktop.
Save shime/2339328 to your computer and use it in GitHub Desktop.
fun with struct
Contact = Struct.new(:first, :last, :email)
p Contact.new(*%w[James Gray james@grayproductions.net])
# >> #<struct Contact first="James",
# last="Gray",
# email="james@grayproductions.net">
p Contact.new(*%w[James Gray])
# >> #<struct Contact first="James", last="Gray", email=nil>
p Contact.new("James")
# >> #<struct Contact first="James", last=nil, email=nil>
p Contact.new
# >> #<struct Contact first=nil, last=nil, email=nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment