﻿{"id":10188,"date":"2021-10-27T07:20:45","date_gmt":"2021-10-26T23:20:45","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=10188"},"modified":"2021-10-26T20:22:08","modified_gmt":"2021-10-26T12:22:08","slug":"crystal-1-2","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/crystal-1-2.html","title":{"rendered":"Crystal 1.2 \u7f16\u7a0b\u8bed\u8a00\u53d1\u5e03"},"content":{"rendered":"<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10192\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2021\/10\/crystal-1-2.jpg\" alt=\"\" width=\"1200\" height=\"600\" \/><\/p>\n<p>\u7f16\u7a0b\u8bed\u8a00 <a href=\"https:\/\/crystal-lang.org\/\" target=\"_blank\" rel=\"nofollow noopener\">Crystal<\/a> 1.2 \u5df2\u7ecf\u53d1\u5e03\uff0c\u5176\u5f00\u53d1\u4eba\u5458\u6b63\u8bd5\u56fe\u5c06 Ruby \u8bed\u8a00\u5f00\u53d1\u7684\u4fbf\u5229\u6027\u4e0e C \u8bed\u8a00\u56fa\u6709\u7684\u9ad8\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u76f8\u7ed3\u5408\u3002Crystal \u8bed\u6cd5\u4e0e Ruby\u5f88\u63a5\u8fd1\uff0c\u4f46\u5e76\u4e0d\u5b8c\u5168\u517c\u5bb9\uff0c\u5c3d\u7ba1\u6709\u4e9b Ruby \u7a0b\u5e8f\u65e0\u9700\u4fee\u6539\u5373\u53ef\u6267\u884c\u3002 \u7f16\u8bd1\u5668\u4ee3\u7801\u662f\u7528 Crystal \u7f16\u5199\u7684\uff0c\u5e76\u5728 Apache 2.0\u8bb8\u53ef\u8bc1\u4e0b\u83b7\u5f97\u8bb8\u53ef\u3002<\/p>\n<p>\u8be5\u8bed\u8a00\u4f7f\u7528\u9759\u6001\u7c7b\u578b\u68c0\u67e5\uff0c\u65e0\u9700\u5728\u4ee3\u7801\u4e2d\u663e\u5f0f\u6307\u5b9a\u53d8\u91cf\u548c\u65b9\u6cd5\u53c2\u6570\u7684\u7c7b\u578b\u5373\u53ef\u5b9e\u73b0\u3002 Crystal \u7a0b\u5e8f\u88ab\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5e76\u5728\u7f16\u8bd1\u65f6\u8fdb\u884c\u5b8f\u8bc4\u4f30\u548c\u4ee3\u7801\u751f\u6210\u3002 \u5728 Crystal \u8bed\u8a00\u7684\u7a0b\u5e8f\u4e2d\uff0c\u5141\u8bb8\u8fde\u63a5\u7528 C \u8bed\u8a00\u7f16\u5199\u7684\u7ed1\u5b9a\u3002 \u4ee3\u7801\u6267\u884c\u7684\u5e76\u884c\u5316\u662f\u4f7f\u7528\u201cspawn\u201d\u5173\u952e\u5b57\u8fdb\u884c\u7684\uff0c\u5b83\u5141\u8bb8\u60a8\u4ee5\u79f0\u4e3a\u7ea4\u7a0b\uff08Fiber\uff09\u7684\u8f7b\u91cf\u7ea7\u7ebf\u7a0b\u7684\u5f62\u5f0f\u5728\u4e0d\u963b\u585e\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u5f02\u6b65\u542f\u52a8\u540e\u53f0\u4efb\u52a1\u3002<\/p>\n<p>\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u5927\u91cf\u5e38\u7528\u529f\u80fd\uff0c\u5305\u62ec\u7528\u4e8e\u5904\u7406 CSV\u3001YAML \u548c JSON \u7684\u5de5\u5177\u3001\u7528\u4e8e\u6784\u5efa HTTP \u670d\u52a1\u5668\u7684\u7ec4\u4ef6\u4ee5\u53ca\u652f\u6301 WebSocket\u3002 \u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f7f\u7528\u201ccrystal play\u201d\u547d\u4ee4\uff0c\u5b83\u4f1a\u751f\u6210\u4e00\u4e2aweb\u754c\u9762\uff08\u9ed8\u8ba4localhost:8080\uff09\uff0c\u7528\u4e8e\u4ee5Crystal\u8bed\u8a00\u4ea4\u4e92\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<p><strong>Crystal 1.2 \u7684\u4e3b\u8981<a href=\"https:\/\/github.com\/crystal-lang\/crystal\/releases\/tag\/1.2.0\" target=\"_blank\" rel=\"nofollow noopener\">\u53d8\u5316<\/a><\/strong>\uff1a<\/p>\n<p>\u6dfb\u52a0\u4e86\u5c06\u6cdb\u578b\u7c7b\u7684\u5b50\u7c7b\u5206\u914d\u7ed9\u7236\u7c7b\u7684\u5143\u7d20\u7684\u529f\u80fd\u3002<\/p>\n<pre class=\"wp-block-preformatted\">class Foo (T); end\r\n   class Bar (T) &lt;Foo (T); end\r\n   x = Foo\r\n   x = Bar<\/pre>\n<p>\u5728\u5b8f\u4e2d\uff0c\u60a8\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528\u4e0b\u5212\u7ebf\u6765\u5ffd\u7565\u201cfor\u201d\u5faa\u73af\u4e2d\u7684\u503c\u3002<\/p>\n<pre class=\"wp-block-preformatted\">{% for _, v, i in {1 =&gt; 2, 3 =&gt; 4, 5 =&gt; 6}%}\r\n     p {{v + i}}\r\n   {% end%}<\/pre>\n<p>\u6dfb\u52a0\u4e86\u201cfile_exists?\u201d \u5b8f\u7684\u65b9\u6cd5\u3002 \u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u3002<br \/>\n\u6807\u51c6\u5e93\u63d0\u4f9b\u5bf9 128 \u4f4d\u6574\u6570\u7684\u652f\u6301\u3002<br \/>\n\u6dfb\u52a0 Indexable::Mutable (T) \u6a21\u5757\u4ee5\u5b9e\u73b0\u5bf9 BitArray \u548c Deque \u7b49\u96c6\u5408\u7684\u6269\u5c55\u64cd\u4f5c\u3002<\/p>\n<pre class=\"wp-block-preformatted\">ba = BitArray.new (10) # ba = BitArray [0000000000]\r\n   ba [0] = true # ba = BitArray [1000000000]\r\n   ba.rotate! (- 1) # ba = BitArray [0100000000]<\/pre>\n<p>\u6dfb\u52a0\u4e86 XML :: Node # namespace_definition \u65b9\u6cd5\u4ee5\u4ece XML \u4e2d\u63d0\u53d6\u7279\u5b9a\u7684\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<p>IO # write_utf8 \u548c URI.encode \u65b9\u6cd5\u5df2\u88ab\u5f03\u7528\uff0c\u5e94\u66ff\u6362\u4e3a IO # write_string \u548c URI.encode_path\u3002<\/p>\n<p>\u5bf9 32 \u4f4d x86 \u67b6\u6784\u7684\u652f\u6301\u5df2\u79fb\u81f3\u7b2c\u4e8c\u7ea7\uff08\u4e0d\u518d\u751f\u6210\u73b0\u6210\u7684\u5305\uff09\u3002 \u6b63\u5728\u51c6\u5907\u8f6c\u79fb\u5230\u5bf9 ARM64 \u67b6\u6784\u7684\u7b2c\u4e00\u7ea7\u652f\u6301\u3002<\/p>\n<p>\u7ee7\u7eed\u4e3a Windows \u5e73\u53f0\u63d0\u4f9b\u5168\u9762\u652f\u6301\u7684\u5de5\u4f5c\u3002 \u6dfb\u52a0\u4e86\u5bf9 Windows \u5957\u63a5\u5b57\u7684\u652f\u6301\u3002<\/p>\n<p>\u5bf9\u4e8e macOS\uff0c\u6dfb\u52a0\u4e86\u4e00\u4e2a\u901a\u7528\u5305\uff0c\u53ef\u5728\u5177\u6709 x86 \u5904\u7406\u5668\u7684\u8bbe\u5907\u548c\u5177\u6709 Apple M1 \u82af\u7247\u7684\u786c\u4ef6\u4e0a\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7a0b\u8bed\u8a00 Crystal 1.2 \u5df2\u7ecf\u53d1\u5e03\uff0c\u5176\u5f00\u53d1\u4eba\u5458\u6b63\u8bd5\u56fe\u5c06 Ruby \u8bed\u8a00\u5f00\u53d1\u7684\u4fbf\u5229\u6027\u4e0e C \u8bed &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[804],"class_list":["post-10188","post","type-post","status-publish","format-standard","hentry","category-zixun","tag-crystal"],"aioseo_notices":[],"views":593,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/10188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=10188"}],"version-history":[{"count":4,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/10188\/revisions"}],"predecessor-version":[{"id":10193,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/10188\/revisions\/10193"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=10188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=10188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=10188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}