Search code examples
rubycrystal-langone-liner

Is there a way to do one-liners in Crystal language?


I'm a user of the Ruby language, and while the idea of using the Crystal language as a one-liner may be silly, the Crystal language is so fast that even when you add up the compile time, it can sometimes run faster than writing one-liners in Ruby. Is there a way to do one-liners in Crystal?


Solution

  • It can, but its definitely not written with that in mind like Perl and to some degree Ruby.

    This is mostly down to Crystal intentionally not inheriting many of the Perlisms that makes this so convenient in Ruby, such as the -p, -n etc command line flags and globals like $_, $' etc.

    Other than that, nothing stops you from running crystal eval 'some code' to your heart's content.