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?
Asked
Active
Viewed 1,046 times
6
-
Maybe some kind of built-in converter? – Vlad Faust Feb 22 '16 at 20:57
1 Answers
17
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

Jonne Haß
- 4,792
- 18
- 30