Developers say that Crystal follows Ruby language syntax. So can I (or would I, in the future) just require a Ruby gem and it magically builds and properly working and so on?
Developers describe Crystal as "Fast as C, slick as Ruby". Crystal is a programming language that resembles Ruby but compiles to native code and tries to be much more efficient, at the cost of disallowing certain dynamic aspects of Ruby.
Ruby gemstones are a variety of the mineral corundum. More specifically, they are the red variety, which is colored by chromium. Other colors of corundum are classified as sapphire. The word “ruby” comes from the Latin word “ruber” for the red hue.
No.
The language evolved a lot and differs significantly from Ruby these days. While it feels a bit like Ruby, if you actually try it you'll quickly understand why that question doesn't even come up except for the most simple gems you can imagine. Just two examples:
Crystal has no single quoted string literals:
'c' # Ok in Ruby and Crystal, but different things,
# a String in Ruby, a Char in Crystal
"a string" # Ok in Ruby and Crystal, a String in both
'a string' # Ok in Ruby, but a compile time error in
# Crystal, since character literals are for a single character
Crystal can't infer the type of empty arrays or hashes:
["foo"] # Ok in Ruby and Crystal, an Array in Ruby,
# an Array(String) in Crystal
{"foo" => "bar"} # Ok in Ruby and Crystal, a Hash
# in Ruby, a Hash(String, String) in Crystal
[] # Ok in Ruby, but a compile time error in Crystal
[] of String # Ok in Crystal, but a syntax error in Ruby
{} # Ok in Ruby, but a compile time error in Crystal
{} of String => String # Ok in Crystal, but a syntax error in Ruby
You can read more for example here or here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With