Skip to content

Instantly share code, notes, and snippets.

@simcap
Last active August 29, 2015 14:05
Show Gist options
  • Save simcap/b1075c592b5b815a99ab to your computer and use it in GitHub Desktop.
Save simcap/b1075c592b5b815a99ab to your computer and use it in GitHub Desktop.
Why I do not like Struct for PORO (Plain Old Ruby Object) ?
Customer = Struct.new(:name, :address)
c = Customer.new('john') # Do not validate construction
c.name # => 'john'
c.address # => nil
c['name'] # => 'john'
# Extra unneeded API to access your property
c['name'] = 'robert'
c.name = 'emile' # Public mutability by default
@simcap
Copy link
Author

simcap commented Nov 18, 2014

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