Last active
October 20, 2015 13:10
-
-
Save lukemorton/ff207f96c71ccd56027e to your computer and use it in GitHub Desktop.
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
class Person < TypedStruct[first_name: String, last_name: String] | |
def full_name | |
"#{first_name} #{last_name}" | |
end | |
end | |
class Person < TypedStruct[first_name: String, | |
last_name: String, | |
age: [Integer, :optional]] | |
def full_name | |
"#{first_name} #{last_name}" | |
end | |
end | |
class Person < TypedStruct | |
field :first_name, String | |
field :last_name, String | |
field :age, Integer, :optional | |
end | |
Person.new('Luke', 'Morton') | |
Person.new(first_name: 'Luke', last_name: 'Morton') | |
Person.new(first_name: 12, last_name: 'Morton') # => raises TypedStruct::TypeError | |
Person.new(first_name: 'Luke') # => raises TypedStruct::FieldMissingError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment