Achieve Static Typing Benefits in Ruby with Keywords Args and Class Constants
04-Oct-2024 317
Achieve Static Typing Benefits in Ruby with Keywords Args and Class Noel Rappin wrote an article on static typing in Ruby that does a great job outlining the various techniques to achieve the benefits often ascribed to static typing. I have two more techniques that address the 80 percent case of typing problems in Ruby: keyword arguments and class constants.
In my experience, most typing issues in Ruby and Rails apps are the result of overuse of hashes as data structures, coupled with the use of symbols to refer to classes instead of using the class itself. Both of these patterns result in indirection between intention and behavior. When you get it wrong—use the wrong hash key, call the wrong dynamically-created method—you get errors that don’t make sense.
Achieve Static Typing Benefits in Ruby with Keywords Args and Class Constants #ruby #rubydeveloper #rubyonrails #Achieve #Static #Typing #Benefits #Keywords #Class #Constants #class https://rubyonrails.ba/link/achieve-static-typing-benefits-in-ruby-with-keywords-args-and-class-constants