Last active
August 29, 2015 14:05
-
-
Save simcap/b1075c592b5b815a99ab to your computer and use it in GitHub Desktop.
Why I do not like Struct for PORO (Plain Old Ruby Object) ?
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For an immutable Struct see https://gist.github.com/simcap/622cac189c9cd0f8665d