Ruby check if string is null or empty

Coming from C# I liked the Frameworks implemented option to check in one go if a given string is null or empty.

Now in Ruby the string class has the method empty? which checks just that i.e. null or empty. But due to the dynamic nature of Ruby one has to tell the interpreter that one would like to have the object as string before you can access the method.

The following code is an example on how it’s done:

some_string.to_s.empty?

Leave a comment