3 ms·
I recently discovered a cool trick for runtime type validation using pattern matching, it goes like this class Person attr_accessor :name, :age def initia
by Alifatisk 2y ago
I 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.