Sustainable Development and More

Sustainable Development and More

Archives
Subscribe

Sustainable Development and More

Archive

Simple Way to Use Types in Ruby

This post by Evan Hahn shows how static typing in Crystal can result in removing some validations you might need in Ruby and thus static types can be a way shorten code.

Sure, sometimes! But, his example of Ruby code that could be shortened leaves some room for improvement. Ruby can be used to create rich and powerful data types, even if they aren't checked by a compiler.

Here's his code (formatted to not be so wide):

def initialize(min_length)
  unless min_length.is_a?(Integer) && 
         min_length >= 0 &&
         min_length <= 255
    raise "Minimum length has to be between 0 and 255"
  end

  @min_length = min_length
end
#2
December 20, 2023
Read more

Welcome to Sustainable Dev

This is my newsletter, that should contain useful and short distillations of information around sustainable web development. Not just with Rails or JavaScript, but anything I might come across or want to share.

TIL

It's hard to keep up with everything, and sometimes I learn something that has been common knowledge for a while. Maybe this happens to you.

While setting this up, I learned that when you create an internal anchor link with e.g. <a name="some_anchor"> you no longer—as of like more than a decade—have to use <a name="some_anchor"> to tell the browser where to send the link. You can just put id="some_anchor" on any element.

#1
December 4, 2023
Read more
  Newer archives
naildrivin5.com
ruby.social
Powered by Buttondown, the easiest way to start and grow your newsletter.