Skip to content

Ruby And Crystal

Dewayne VanHoozer edited this page Jul 6, 2022 · 7 revisions

I created the first prototype of justprep as a Ruby gem. Ruby is the best language I have ever found for creating prototypes. Its quick, easily adaptable, and fun to program.

Crystal is a compiled language that uses a syntax very close to Ruby. It is possible to write Ruby code that is also compiled by Crystal. I have thought for a long time that there should be a way to take a normal Ruby program and either manually or automatically convert is source into source that is compatible with Crystal. I'm still working on the automatic part.

The justprep repository contains both the Ruby gem implementation and the Crystal implementation. Each implementation does the same thing the same way. Within the Ruby directory at "../ruby/lib/justprep/common/" you will find files with the extension "*.crb" which I take to mean "Crystal Ruby" - sometimes I think "Compiled Ruby" wouldn't you?

These *.crb files contain source that is both executable in Ruby and compilable in Crystal.

Ruby Modifications for Crystal Compatibility

The Ruby file crystal_methods.rb isolates the duck typing I did to alias Ruby methods to the method names used by Crystal's libraries. Its not a complete set. I only implemented what I need for justprep.

I've started a project using synvert-ruby to add snippets for doing Ruby to Crystal conversions. My project for synvert is in the crystal branch at synvert-snippets.

There is also a Ruby gem that is not too old that attempts to rewrite Ruby source code to be Crystal compilable source: ruby_crystal_codemod

Clone this wiki locally