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?
Would one be able to use Ruby gems with Crystal?
Asked Answered
Maybe some kind of built-in converter? –
Fletcherfletcherism
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
© 2022 - 2024 — McMap. All rights reserved.