Safe code evaluation in Ruby with $SAFE

As you probably know, you can use eval() to evaluate Ruby code from Ruby. But evaluating things that come from the outside of the program like user inputs can be dangerous. Why they can be dangerous you ask? eval() evaluates anything as we would program it ourselves. Basically anything can happen. That’s why it’s best to avoid eval() for such inputs altogether. But we can evaluate Ruby in a safer manner too; with $SAFE. Continue reading

Running test/unit suites with Minitest

Sometimes it happens that you want to run an old test suite, but you don’t have a correct version of the testing framework available. That happens a lot in Fedora
since tooling around RPM supports only one version of each component and new rubies does not come with test/unit anymore. As we still need to run the tests, we have two options. Either go ahead and update the whole test suite to a new version or just use Ruby’s dynamic nature to actually run it. Let’s look how the latter can look like. Continue reading