2 ms·
What About Static Typing in Ruby?
- Alifatisk 2y agoI recently discovered a cool trick for runtime type validation using pattern matching, it goes like this class Person attr_accessor :name, :age def initialize(name:, age:) name => ::String age => ::Numeric @name = name @age = age end end Src: https://ruby.social/@aristotelesbr/110533722544270023?utm_source=substack&utm_medium=email https://ruby.social/@aristotelesbr/110533722544270023?utm_so...
- sodapopcan 2y agoRuby should likely strive to this: def initialize(name => ::String, age => ::Numeric) @name = name @age = age end or better yet? def initialize(name => String, age => Numeric) @name = name @age = age end I've been out of Ruby for a while so I don't understand by why the top level qualifiers are necessary.