When creating data types in Ruby, I often make a factory method that does 2 things you can't do in an initializer:

1 - if the argument is nil, return nil
2 - if the argument is already of the data type, return it

https://gist.github.com/davetron5000/1a6b394f4295f1b70062baab013d297f#file-factory-rb
Post image

Comments