是否可以将红宝石与水晶一起使用



开发人员说Crystal遵循Ruby语言语法。那么我(或者将来我会)只需要一个 Ruby 宝石,它就会神奇地构建并正常工作等等吗?

No.

该语言发展了很多,如今与Ruby有很大不同。虽然感觉有点像 Ruby,但如果你真的尝试过,你很快就会明白为什么除了你能想象到的最简单的宝石之外,这个问题甚至不会出现。仅举两个例子:

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

例如,您可以在此处或此处阅读更多内容。

相关内容

  • 没有找到相关文章

最新更新