Strong type checking for Ruby
22-Nov-2018 1756
If you're unfamiliar with using keyword - this is refinement - a relatively new feature in Ruby (since 2.0). It's kind of monkey-patch, but with strict scope. Learn more about refinements.This refinement adds type!() and not_nil! methods to Object class so you can call it on almost much any object (except those inherited from BasicObject, but these are rare).The method will raise an exception if self is not an instance of one of the classes passed as arguments. The tricky part, however, is to get the variable name on which it's called. You need this to get a nice error message telling you exactly which variable has wrong type, not just an abstract TypeError. That's why we need Ruby 2.6 with its new RubyVM::AST.
Strong type checking for Ruby #ruby #rubydeveloper #rubyonrails #Strong #checking #type https://rubyonrails.ba/link/strong-type-checking-for-ruby