Ruby

Enum types in Ruby

When I start a new project in Ruby, the first module I copy over is my custom little enum.rb.

Many popular programming languages have built-in support for enums. C, C++, C#, Go, Java, Rust, Swift, but also looser-typed languages like PHP and Python.

Ruby doesn’t have native support for enum types, but it’s not hard to add and add some clarity and cleanliness to your code.

URL Validation in Ruby

When it comes to validation, I don’t like to re-invent the wheel. Many programming languages have built-in modules for common types of data, such as a URL.

In Ruby, we have the URI module which is often used to generate, parse, and manipulate a URI. It has a method URI.parse which accepts a string and creates an instance of a URI.

For a time, I thought this was a decent approach to use. You could validate a string as a URL doing something like:

Mossy is Born!

Faced with having to script out schema and objects from a SQL Server database, the only option was using SMO. That’s a Windows-only solution that has some known bugs and performance problems. Using the management views in SQL Server you can script everything out yourself. So I created mossy to do that in Ruby. It can script out a whole database in under 15 queries and depending on the size of modules, should only takes a few seconds.