开发人员说 Crystal 遵循 Ruby 语言语法。那么我(或者我将来会不会)只需要一个 Ruby gem 并且它可以神奇地构建并正常工作等等吗?
问问题
953 次
1 回答
16
不。
如今,该语言发展了很多,并且与 Ruby 有很大不同。虽然感觉有点像 Ruby,但如果你真正尝试过,你会很快理解为什么除了你能想象到的最简单的 gem 之外,这个问题甚至没有出现。仅举两个例子:
Crystal 没有单引号字符串文字:
'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 无法推断空数组或散列的类型:
["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
于 2016-02-23T11:12:34.457 回答