{"id":35,"date":"2024-01-07T17:13:46","date_gmt":"2023-05-09T00:52:48","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/index.php\/2023\/11\/30\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/"},"modified":"2025-07-31T21:46:32","modified_gmt":"2025-07-31T13:46:32","slug":"%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/","title":{"rendered":"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528"},"content":{"rendered":"<h3>\u5f15\u8a00<\/h3>\n<p>\u5f53\u4f60\u7f16\u5199\u7a0b\u5e8f\u65f6\uff0c\u4f60\u9700\u8981\u4f7f\u7528\u6570\u636e\u7c7b\u578b\u6765\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u3002\u6570\u636e\u7c7b\u578b\u544a\u8bc9\u8ba1\u7b97\u673a\u5982\u4f55\u5904\u7406\u7a0b\u5e8f\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u51b3\u5b9a\u4e86\u4f60\u53ef\u4ee5\u5bf9\u6570\u636e\u6267\u884c\u54ea\u4e9b\u64cd\u4f5c\u3002<\/p>\n<p>\u7406\u89e3\u6570\u636e\u7c7b\u578b\u7684\u4e00\u79cd\u65b9\u5f0f\u662f\u601d\u8003\u6211\u4eec\u5728\u73b0\u5b9e\u4e16\u754c\u4e2d\u4f7f\u7528\u7684\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u4f7f\u7528\u6574\u6570\uff080\u30011\u30012&#8230;\uff09\u3001\u8d1f\u6574\u6570\uff08-1\u30010\u30011&#8230;\uff09\u548c\u65e0\u7406\u6570\uff08\u03c0\uff09\u3002<\/p>\n<p>\u901a\u5e38\u5728\u6570\u5b66\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u5b57\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u5e76\u5f97\u5230\u67d0\u79cd\u7b54\u6848\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u80fd\u60f3\u5c065\u52a0\u4e0a\u03c0\u3002<\/p>\n<pre class=\"post-pre\"><code>5 + \u03c0\r\n<\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u65b9\u7a0b\u4f5c\u4e3a\u7b54\u6848\u4fdd\u7559\u4ee5\u89e3\u51b3\u65e0\u7406\u6570\u7684\u95ee\u9898\uff0c\u6216\u8005\u6211\u4eec\u53ef\u4ee5\u5c06\u03c0\u56db\u820d\u4e94\u5165\u5230\u5c0f\u6570\u70b9\u540e\u51e0\u4f4d\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u6570\u5b57\u76f8\u52a0\u3002<\/p>\n<pre class=\"post-pre\"><code>5 + \u03c0 = 5 + 3.14 = 8.14\r\n<\/code><\/pre>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528\u53e6\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u6587\u5b57\uff0c\u6765\u8bc4\u4f30\u6570\u5b57\uff0c\u4e8b\u60c5\u5c31\u5f00\u59cb\u53d8\u5f97\u4e0d\u592a\u6709\u610f\u4e49\u3002\u6211\u4eec\u8981\u5982\u4f55\u89e3\u51b3\u4e0b\u9762\u7684\u65b9\u7a0b\uff1f<\/p>\n<pre class=\"post-pre\"><code>sky + 8\r\n<\/code><\/pre>\n<p>\u8fd9\u4e0d\u662f\u6211\u4eec\u80fd\u7acb\u523b\u89e3\u51b3\u7684\u95ee\u9898\u3002\u8ba1\u7b97\u673a\u4e5f\u65e0\u6cd5\u89e3\u51b3\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u6570\u636e\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u7c7b\u578b\u3002\u201c\u5929\u7a7a\u201d\u662f\u4e00\u4e2a\u8bcd\uff0c\u800c8\u662f\u4e00\u4e2a\u6574\u6570\u3002\u5f53\u6211\u4eec\u7f16\u5199\u7a0b\u5e8f\u65f6\uff0c\u6211\u4eec\u5fc5\u987b\u5c0f\u5fc3\u5730\u8d4b\u503c\u5e76\u4f7f\u7528\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u7b49\u64cd\u4f5c\u5bf9\u5176\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u6709\u5173Ruby\u539f\u751f\u6570\u636e\u7c7b\u578b\u6700\u91cd\u8981\u7684\u77e5\u8bc6\uff1a\u6574\u578b\u3001\u6d6e\u70b9\u578b\u3001\u5b57\u7b26\u4e32\u3001\u7b26\u53f7\u3001\u6570\u7ec4\u548c\u6563\u5217\u3002\u8fd9\u5e76\u4e0d\u662f\u5bf9\u6570\u636e\u7c7b\u578b\u8fdb\u884c\u8be6\u5c3d\u7684\u7814\u7a76\uff0c\u4f46\u5b83\u5c06\u5e2e\u52a9\u60a8\u719f\u6089\u5728\u7a0b\u5e8f\u4e2d\u53ef\u7528\u7684\u9009\u9879\u3002<\/p>\n<p>\u7136\u540e\u60a8\u5c06\u5b66\u4e60\u52a8\u6001\u7c7b\u578b\u3002Ruby\u7a0b\u5e8f\u6839\u636e\u53d8\u91cf\u6240\u5305\u542b\u7684\u5185\u5bb9\u6765\u786e\u5b9a\u6570\u636e\u7c7b\u578b\uff0c\u56e0\u6b64\u4e86\u89e3\u52a8\u6001\u7c7b\u578b\u7684\u5de5\u4f5c\u539f\u7406\u5c06\u5e2e\u52a9\u60a8\u907f\u514d\u5728\u81ea\u5df1\u7684\u7a0b\u5e8f\u4e2d\u9047\u5230\u68d8\u624b\u7684\u60c5\u51b5\u3002\u800c\u4e14\u7531\u4e8e\u53d8\u91cf\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u503c\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u8bc6\u522b\u53d8\u91cf\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u4ece\u5b66\u4e60\u5982\u4f55\u5728Ruby\u4e2d\u5904\u7406\u6574\u6570\u5f00\u59cb\u3002<\/p>\n<h2>\u6574\u6570<\/h2>\n<p>\u548c\u6570\u5b66\u4e00\u6837\uff0c\u5728\u8ba1\u7b97\u673a\u7f16\u7a0b\u4e2d\uff0c\u6574\u6570\u662f\u6307\u53ef\u4ee5\u662f\u6b63\u6570\u3001\u8d1f\u6570\u6216\u80050\uff08\u2026\uff0c-1\uff0c0\uff0c1\uff0c\u2026\uff09\u7684\u6574\u6570\u3002\u6574\u6570\u4e5f\u5e38\u88ab\u79f0\u4e3a<code>int<\/code>\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u50cf\u8fd9\u6837\u6253\u5370\u51fa\u4e00\u4e2a\u6574\u6570\u3002<\/p>\n<pre class=\"post-pre\"><code>print -25\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>-25\r\n<\/code><\/pre>\n<p>\u4f60\u8fd8\u53ef\u4ee5\u628a\u6574\u6570\u5b58\u50a8\u5728\u4e00\u4e2a\u53d8\u91cf\u4e2d\uff0c\u5e76\u901a\u8fc7\u5f15\u7528\u53d8\u91cf\u6765\u6253\u5370\u51fa\u8be5\u503c\u3002<\/p>\n<pre class=\"post-pre\"><code>my_int = -25\r\nprint my_int\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>-25\r\n<\/code><\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6574\u6570\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u4ee5\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u7684\u548c\uff0c\u5e76\u6253\u5370\u51fa\u7ed3\u679c\u3002<\/p>\n<pre class=\"post-pre\"><code>sum = 116 - 68\r\nprint sum\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>48\r\n<\/code><\/pre>\n<p>\u5f53\u6211\u4eec\u5199\u5927\u6570\u5b57\u65f6\uff0c\u6211\u4eec\u503e\u5411\u4e8e\u4f7f\u7528\u9017\u53f7\u6765\u4f7f\u5176\u66f4\u6613\u8bfb\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u4f1a\u5c06\u201c\u4e00\u767e\u4e07\u201d\u5199\u4e3a1,000,000\u3002\u4f60\u4e0d\u80fd\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\u9017\u53f7\uff0c\u4f46\u662fRuby\u5141\u8bb8\u4f60\u4f7f\u7528\u4e0b\u5212\u7ebf\uff08<code>_<\/code>\uff09\u5b57\u7b26\u6765\u4f7f\u5927\u6570\u5b57\u66f4\u6613\u8bfb\u3002<\/p>\n<p>\u8bd5\u4e00\u4e0b\u5427\u3002<\/p>\n<div>\u5927\u6570\u5b57\u7684Ruby\u6587\u4ef6\u3002<\/div>\n<pre class=\"post-pre\"><code>large_number = 1_234_567\r\nprint large_number\r\n<\/code><\/pre>\n<p>\u60a8\u5c06\u770b\u5230\u6574\u6570\u7684\u8f93\u51fa\u7ed3\u679c\u6ca1\u6709\u4e0b\u5212\u7ebf\uff1a<\/p>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>1234567\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u9700\u8981\u5728\u7a0b\u5e8f\u4e2d\u8868\u793a\u5927\u6570\u5b57\uff0c\u4e0b\u5212\u7ebf\u53ef\u4ee5\u8ba9\u4f60\u7f16\u5199\u66f4\u6613\u8bfb\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5f53\u4f60\u5bf9Ruby\u8bed\u8a00\u4e86\u89e3\u5f97\u66f4\u591a\u65f6\uff0c\u4f60\u5c06\u6709\u66f4\u591a\u7684\u673a\u4f1a\u6765\u5904\u7406\u6574\u6570\u3002\u73b0\u5728\u8ba9\u6211\u4eec\u6765\u770b\u770b\u5982\u4f55\u5904\u7406\u5b9e\u6570\u3002<\/p>\n<h2>\u6d6e\u70b9\u6570<\/h2>\n<p>\u6d6e\u70b9\u6570\u6216\u8005\u6d6e\u70b9\u578b\u4ee3\u8868\u7740\u5b9e\u6570\u3002\u5b9e\u6570\u65e2\u53ef\u4ee5\u662f\u6709\u7406\u6570\uff0c\u4e5f\u53ef\u4ee5\u662f\u65e0\u7406\u6570\uff1b\u6bd4\u59829.0\u6216\u8005-116.42\u8fd9\u79cd\u5305\u542b\u5c0f\u6570\u90e8\u5206\u7684\u6570\u5b57\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5728Ruby\u7a0b\u5e8f\u4e2d\uff0c\u6d6e\u70b9\u6570\u5c31\u662f\u5305\u542b\u5c0f\u6570\u70b9\u7684\u6570\u5b57\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u50cf\u6253\u5370\u6574\u6570\u4e00\u6837\u6253\u5370\u6d6e\u70b9\u6570\uff0cRuby\u4e2d\u662f\u5141\u8bb8\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code>print 17.3\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>17.3\r\n<\/code><\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u5e76\u8d4b\u4e88\u4e00\u4e2a\u6d6e\u70b9\u503c\u3002<\/p>\n<pre class=\"post-pre\"><code>my_float = 17.3\r\nprint my_float\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>17.3\r\n<\/code><\/pre>\n<p>\u800c\u4e14\uff0c\u5c31\u50cf\u5bf9\u6574\u6570\u4e00\u6837\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728Ruby\u4e2d\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n<pre class=\"post-pre\"><code>sum = 564.0 + 365.24\r\nprint sum\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>929.24\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u5728Ruby\u4e2d\u628a\u4e00\u4e2a\u6d6e\u70b9\u6570\u52a0\u5230\u4e00\u4e2a\u6574\u6570\u4e0a\uff0c\u90a3\u4e48\u7ed3\u679c\u4f1a\u662f\u4e00\u4e2a\u6d6e\u70b9\u6570\u3002<\/p>\n<pre class=\"post-pre\"><code>sum = 564 + 365.24\r\nprint sum\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>929.24\r\n<\/code><\/pre>\n<p>\u5728Ruby\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u6570\u6ca1\u6709\u5c0f\u6570\u70b9\uff0c\u5b83\u5c06\u88ab\u89c6\u4e3a\u6574\u6570\uff08\u4f8b\u5982138\uff09\uff0c\u800c\u5982\u679c\u4e00\u4e2a\u6570\u6709\u5c0f\u6570\u70b9\uff0c\u5219\u88ab\u89c6\u4e3a\u6d6e\u70b9\u6570\uff08\u4f8b\u5982138.0\uff09\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u770bRuby\u4e2d\u7684\u5e03\u5c14\u503c\u3002<\/p>\n<h2>\u5e03\u5c14\u6570\u636e\u7c7b\u578b<\/h2>\n<p>\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\uff0c\u5e03\u5c14\u503c\u7528\u4e8e\u8868\u793a\u4e0e\u903b\u8f91\u5206\u652f\u76f8\u5173\u7684\u771f\u503c\uff0c\u4ece\u800c\u4e3a\u7b97\u6cd5\u63d0\u4f9b\u4fe1\u606f\u3002\u5728Ruby\u4e2d\uff0c\u6211\u4eec\u7528\u4e24\u4e2a\u503c\u4e4b\u4e00\u6765\u8868\u793a\u8fd9\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5373<code>true<\/code>\u6216<code>false<\/code>\u3002<\/p>\n<p>\u5728\u6570\u5b66\u4e2d\uff0c\u8bb8\u591a\u8fd0\u7b97\u4f1a\u7ed9\u6211\u4eec\u5e26\u6765\u53ef\u4ee5\u5224\u65ad\u4e3a\u771f\u6216\u5047\u7684\u7b54\u6848\u3002<\/p>\n<ul class=\"post-ul\">\n<li>\u5927\u4e8e<\/li>\n<li>500 &gt; 100 \u4e3a\u771f<\/li>\n<li>1 &gt; 5 \u4e3a\u5047<\/li>\n<li>\u5c0f\u4e8e<\/li>\n<li>200 &lt; 400 \u4e3a\u771f<\/li>\n<li>4 &lt; 2 \u4e3a\u5047<\/li>\n<li>\u7b49\u4e8e<\/li>\n<li>5 = 5 \u4e3a\u771f<\/li>\n<li>500 = 400 \u4e3a\u5047<\/li>\n<\/ul>\n<p>\u5c31\u50cf\u6570\u5b57\u4e00\u6837\uff0c\u4f60\u53ef\u4ee5\u5c06<code>true<\/code>\u6216<code>false<\/code>\u503c\u5b58\u50a8\u5728\u4e00\u4e2a\u53d8\u91cf\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code>result = 5 &gt; 8\r\n<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>print()<\/code>\u51fd\u6570\u5c06\u5e03\u5c14\u503c\u6253\u5370\u51fa\u6765\u3002<\/p>\n<pre class=\"post-pre\"><code>print result\r\n<\/code><\/pre>\n<p>\u7531\u4e8e5\u4e0d\u5927\u4e8e8\uff0c\u60a8\u5c06\u770b\u5230\u4ee5\u4e0b\u7ed3\u679c\uff1a<\/p>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u968f\u7740\u60a8\u7f16\u5199\u66f4\u591aRuby\u7a0b\u5e8f\uff0c\u60a8\u5c06\u66f4\u52a0\u719f\u6089\u5e03\u5c14\u7c7b\u578b\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u4ee5\u53ca\u4e0d\u540c\u7684\u51fd\u6570\u548c\u64cd\u4f5c\u5982\u4f55\u8bc4\u4f30\u4e3a<code>true<\/code>\u6216<code>false<\/code>\uff0c\u4ece\u800c\u6539\u53d8\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u6765\u63a2\u7d22\u5982\u4f55\u5728\u6211\u4eec\u7684\u7a0b\u5e8f\u4e2d\u5904\u7406\u6587\u672c\u3002<\/p>\n<h2>\u5b57\u7b26\u4e32\uff08String\uff09<\/h2>\n<p>\u5b57\u7b26\u4e32\u662f\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u5e8f\u5217\uff0c\u4f8b\u5982\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u7b26\u53f7\u3002\u5728Ruby\u4e2d\uff0c\u5b57\u7b26\u4e32\u4e3b\u8981\u5b58\u5728\u4e8e\u5355\u5f15\u53f7\uff08<code>'<\/code>\uff09\u6216\u53cc\u5f15\u53f7\uff08<code>\"<\/code>\uff09\u4e4b\u95f4\u3002\u56e0\u6b64\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u9700\u8981\u5c06\u5b57\u7b26\u5e8f\u5217\u7528\u5f15\u53f7\u62ec\u8d77\u6765\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token string-literal\"><span class=\"token string\">\"\u8fd9\u662f\u4e00\u4e2a\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u3002\"<\/span><\/span>\r\n<\/code><\/pre>\n<p>\u7ecf\u5178\u7684\u201cHello, World\uff01\u201d\u5c0f\u7a0b\u5e8f\u5c55\u793a\u4e86\u5b57\u7b26\u4e32\u5728\u8ba1\u7b97\u673a\u7f16\u7a0b\u4e2d\u662f\u5982\u4f55\u88ab\u4f7f\u7528\u7684\uff0c\u56e0\u4e3a\u6784\u6210\u201cHello, World!\u201d\u8fd9\u4e2a\u77ed\u8bed\u7684\u5b57\u7b26\u7ec4\u6210\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002<\/p>\n<pre class=\"post-pre\"><code>print <span class=\"token string-literal\"><span class=\"token string\">\"Hello, World!\"<\/span><\/span>\r\n<\/code><\/pre>\n<p>\u4e0e\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u4e00\u6837\uff0c\u60a8\u53ef\u4ee5\u5728\u53d8\u91cf\u4e2d\u5b58\u50a8\u5b57\u7b26\u4e32\u3002<\/p>\n<pre class=\"post-pre\"><code>output <span class=\"token operator\">=<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Hello, World!\"<\/span><\/span>\r\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8c03\u7528\u53d8\u91cf\u6765\u6253\u5370\u5b57\u7b26\u4e32\u3002<\/p>\n<pre class=\"post-pre\"><code>print output\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Hello, World!<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>\u548c\u6570\u5b57\u4e00\u6837\uff0c\u5728\u6211\u4eec\u7684\u7a0b\u5e8f\u4e2d\u53ef\u4ee5\u5bf9\u5b57\u7b26\u4e32\u6267\u884c\u8bb8\u591a\u64cd\u4f5c\uff0c\u4ee5\u4fbf\u64cd\u7eb5\u5b83\u4eec\u4ee5\u8fbe\u5230\u6211\u4eec\u6240\u5bfb\u6c42\u7684\u7ed3\u679c\u3002\u5b57\u7b26\u4e32\u5bf9\u4e8e\u5411\u7528\u6237\u4f20\u9012\u4fe1\u606f\u4ee5\u53ca\u7528\u6237\u5411\u7a0b\u5e8f\u4f20\u9012\u4fe1\u606f\u90fd\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u6709\u65f6\u5019\u4f60\u9700\u8981\u5904\u7406\u4e00\u4e9b\u6570\u636e\u5217\u8868\u3002\u8fd9\u5c31\u662f\u6570\u7ec4\u6d3e\u4e0a\u7528\u573a\u7684\u5730\u65b9\u3002<\/p>\n<h2>\u6570\u7ec4\uff08Array\uff09<\/h2>\n<h3>\u6570\u7ec4\uff08Arrays\uff09<\/h3>\n<p>\u6570\u7ec4\u662f\u4e00\u79cd\u53ef\u4ee5\u5728\u5355\u4e2a\u53d8\u91cf\u4e2d\u5b58\u50a8\u591a\u4e2a\u503c\u7684\u6570\u636e\u7ed3\u6784\u3002\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\u5305\u542b\u4e00\u4e2a\u503c\u5217\u8868\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u8fed\u4ee3\u3002\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u9879\u76ee\u6216\u503c\u88ab\u79f0\u4e3a\u4e00\u4e2a<strong>\u5143\u7d20<\/strong>\u3002<\/p>\n<p>\u901a\u8fc7\u5728\u65b9\u62ec\u53f7 <code>[ ]<\/code> \u4e2d\u6307\u5b9a\u9017\u53f7\u5206\u9694\u7684\u503c\u6765\u5b9a\u4e49\u6570\u7ec4\u3002<\/p>\n<p>\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token punctuation\">[<\/span><span class=\"token operator\">-<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">-<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">]<\/span>\r\n<\/code><\/pre>\n<p>\u4e00\u4e2a\u6d6e\u70b9\u6570\u6570\u7ec4\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token punctuation\">[<\/span><span class=\"token number\">3.14<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">9.23<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">111.11<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">312.12<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1.05<\/span><span class=\"token punctuation\">]<\/span>\r\n<\/code><\/pre>\n<p>\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token punctuation\">[<\/span><span class=\"token string-literal\"><span class=\"token string\">'shark'<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">'cuttlefish'<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">'squid'<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">'mantis shrimp'<\/span><\/span><span class=\"token punctuation\">]<\/span>\r\n<\/code><\/pre>\n<p>\u50cf\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u4e00\u6837\uff0c\u4f60\u53ef\u4ee5\u5c06\u6570\u7ec4\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\u3002<\/p>\n<pre class=\"post-pre\"><code>sea_creatures <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string-literal\"><span class=\"token string\">'shark'<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">'cuttlefish'<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">'squid'<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">'mantis shrimp'<\/span><\/span><span class=\"token punctuation\">]<\/span>\r\n<\/code><\/pre>\n<p>\u5982\u679c\u6211\u4eec\u6253\u5370\u8fd9\u4e2a\u53d8\u91cf\uff0c\u8f93\u51fa\u7ed3\u679c\u5c06\u4e0e\u6211\u4eec\u521b\u5efa\u7684\u6570\u7ec4\u5b8c\u5168\u76f8\u540c\u3002<\/p>\n<pre class=\"post-pre\"><code>print sea_creatures\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>['shark', 'cuttlefish', 'squid', 'mantis shrimp']\r\n<\/code><\/pre>\n<p>\u901a\u8fc7\u4f7f\u7528\u7d22\u5f15\u53f7\u6765\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5355\u4e2a\u5143\u7d20\uff0c\u7d22\u5f15\u53f7\u4ece 0 \u5f00\u59cb\u3002<\/p>\n<pre class=\"post-pre\"><code>puts sea_creatures<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># shark<\/span>\r\nputs sea_creatures<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># squid<\/span>\r\n<\/code><\/pre>\n<p>\u8981\u6253\u5370\u51fa\u6700\u540e\u4e00\u4e2a\u503c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15 <code>-1<\/code>\u3002Ruby \u8fd8\u63d0\u4f9b\u4e86 <code>.first<\/code> \u548c <code>.last<\/code> \u65b9\u6cd5\uff0c\u5206\u522b\u7528\u4e8e\u83b7\u53d6\u6570\u7ec4\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002<\/p>\n<pre class=\"post-pre\"><code>puts sea_creatures<span class=\"token punctuation\">.<\/span>first <span class=\"token comment\"># shark<\/span>\r\nputs sea_creatures<span class=\"token punctuation\">.<\/span>last <span class=\"token comment\"># mantis shrimp<\/span>\r\n<\/code><\/pre>\n<p>\u5728 Ruby \u4e2d\uff0c\u6570\u7ec4\u53ef\u4ee5\u5305\u542b\u591a\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u4f60\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u3001\u7b26\u53f7\u751a\u81f3\u5176\u4ed6\u6570\u7ec4\u5b58\u50a8\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code>record <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span>\r\n<span class=\"token symbol\">:en<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token string-literal\"><span class=\"token string\">\"Sammy\"<\/span><\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token number\">42<\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token punctuation\">[<\/span>\r\n<span class=\"token string-literal\"><span class=\"token string\">\"coral\"<\/span><\/span><span class=\"token punctuation\">,<\/span>\r\n<span class=\"token string-literal\"><span class=\"token string\">\"reef\"<\/span><\/span>\r\n<span class=\"token punctuation\">]<\/span>\r\n<span class=\"token punctuation\">]<\/span>\r\n<\/code><\/pre>\n<p>\u5728 Ruby \u4e2d\uff0c\u6570\u7ec4\u662f\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u6dfb\u52a0\u503c\u3001\u5220\u9664\u503c\u751a\u81f3\u4fee\u6539\u6570\u7ec4\u4e2d\u7684\u6761\u76ee\u3002<\/p>\n<p>\u6709\u65f6\u6211\u4eec\u5728\u7a0b\u5e8f\u4e2d\u9700\u8981\u4e00\u79cd\u7528\u6765\u6807\u8bb0\u4e8b\u7269\u7684\u65b9\u6cd5\u3002\u8fd9\u5c31\u662f\u7b26\u53f7\u7684\u4f5c\u7528\u6240\u5728\u3002<\/p>\n<h3>\u7b26\u53f7\uff08Symbols\uff09<\/h3>\n<p>\u7b26\u53f7\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5728 Ruby \u7a0b\u5e8f\u4e2d\u5145\u5f53\u6807\u7b7e\u6216\u6807\u8bc6\u7b26\u7684\u4f5c\u7528\u3002\u7b26\u53f7\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u4e0d\u80fd\u88ab\u6539\u53d8\u3002\u4e00\u4e2a\u7b26\u53f7\u770b\u8d77\u6765\u50cf\u4e00\u4e2a\u6ca1\u6709\u503c\u7684\u53d8\u91cf\u58f0\u660e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b26\u53f7\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token symbol\">:time_zone<\/span>\r\n<\/code><\/pre>\n<p>\u5728 Ruby \u4e2d\uff0c\u901a\u5e38\u4f7f\u7528\u7b26\u53f7\u6765\u6807\u8bc6\u91cd\u8981\u7684\u5185\u5bb9\uff0c\u800c\u5bf9\u4e8e\u9700\u8981\u5904\u7406\u6216\u64cd\u4f5c\u7684\u6587\u672c\uff0c\u5219\u4f7f\u7528\u5b57\u7b26\u4e32\u3002\u5728 Ruby \u7a0b\u5e8f\u4e2d\uff0c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u90fd\u662f\u5355\u72ec\u7684\u5bf9\u8c61\uff0c\u5177\u6709\u81ea\u5df1\u5728\u5185\u5b58\u4e2d\u7684\u552f\u4e00\u4f4d\u7f6e\uff0c\u5373\u4f7f\u8fd9\u4e9b\u5b57\u7b26\u4e32\u662f\u76f8\u540c\u7684\u3002<\/p>\n<p>\u4f46\u662f\u5982\u679c\u60a8\u591a\u6b21\u5f15\u7528\u76f8\u540c\u7684\u7b26\u53f7\uff0c\u90a3\u4e48\u60a8\u5728\u7a0b\u5e8f\u4e2d\u5f15\u7528\u7684\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u5728\u5f15\u7528\u540c\u4e00\u4e2a\u5185\u5b58\u4f4d\u7f6e\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u7814\u7a76\u54c8\u5e0c\u65f6\uff0c\u4f60\u4f1a\u770b\u5230\u8fd9\u4e2a\u6982\u5ff5\u7684\u5b9e\u9645\u8fd0\u7528\uff0c\u5b83\u5141\u8bb8\u4f60\u5c06\u952e\u4e0e\u503c\u5173\u8054\u8d77\u6765\u3002<\/p>\n<h3>\u54c8\u5e0c\uff08Hashes\uff09<\/h3>\n<p>\u8fd9\u662f\u6587\u7ae0\u300a\u7406\u89e3 Ruby \u4e2d\u7684\u6570\u636e\u7c7b\u578b\u300b\u7684\u7b2c4\u90e8\u5206\uff08\u51716\u90e8\u5206\uff09\u3002<\/p>\n<p>\u54c8\u5e0c\uff08Hash\uff09\u662f\u4e00\u79cd\u7c7b\u4f3c\u5b57\u5178\u7684\u952e\u503c\u5bf9\u96c6\u5408\u3002\u8fd9\u4e9b\u952e\u503c\u5bf9\u63d0\u4f9b\u4e86\u4e00\u79cd\u4fbf\u6377\u7684\u65b9\u5f0f\u6765\u5b58\u50a8\u548c\u8bbf\u95ee\u6570\u636e\u3002\u54c8\u5e0c\u901a\u5e38\u7528\u4e8e\u5b58\u50a8\u76f8\u5173\u7684\u6570\u636e\uff0c\u4f8b\u5982\u7528\u6237\u4fe1\u606f\u3002\u4f60\u53ef\u4ee5\u50cf\u8fd9\u6837\u5b9a\u4e49\u4e00\u4e2a\u54c8\u5e0c\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token punctuation\">{<\/span><span class=\"token string-literal\"><span class=\"token string\">\"first_name\"<\/span><\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Sammy\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"last_name\"<\/span><\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Shark\"<\/span><\/span><span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u50cf\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u4e00\u6837\uff0c\u5c06\u54c8\u5e0c\u8d4b\u503c\u7ed9\u53d8\u91cf\uff1a<\/p>\n<pre class=\"post-pre\"><code>user <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string-literal\"><span class=\"token string\">\"first_name\"<\/span><\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Sammy\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"last_name\"<\/span><\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Shark\"<\/span><\/span><span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p>\u4ece\u54c8\u5e0c\u4e2d\u68c0\u7d22\u503c\u65f6\uff0c\u4f7f\u7528\u5bf9\u5e94\u7684\u952e\u6765\u83b7\u53d6\u503c\uff1a<\/p>\n<pre class=\"post-pre\"><code>print user<span class=\"token punctuation\">[<\/span><span class=\"token string-literal\"><span class=\"token string\">\"first_name\"<\/span><\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># \"Sammy\"<\/span>\r\nprint user<span class=\"token punctuation\">[<\/span><span class=\"token string-literal\"><span class=\"token string\">\"last_name\"<\/span><\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># \"Shark\"<\/span>\r\n<\/code><\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7b26\u53f7\uff08Symbol\uff09\u4f5c\u4e3a\u54c8\u5e0c\u4e2d\u7684\u952e\uff0c\u800c\u4e0d\u662f\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre class=\"post-pre\"><code>user <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token symbol\">:first_name<\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Sammy\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token symbol\">:last_name<\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Shark\"<\/span><\/span><span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p>\u5efa\u8bae\u5c3d\u53ef\u80fd\u4f7f\u7528\u7b26\u53f7\u4f5c\u4e3a\u54c8\u5e0c\u952e\u3002\u6bcf\u4e2a\u7b26\u53f7\u5b9e\u4f8b\u90fd\u6307\u5411\u76f8\u540c\u7684\u5bf9\u8c61\uff0c\u800c\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5b9e\u4f8b\u90fd\u6307\u5411\u4e00\u4e2a\u552f\u4e00\u7684\u5bf9\u8c61\u3002\u4f7f\u7528\u7b26\u53f7\u4f5c\u4e3a\u952e\u53ef\u4ee5\u83b7\u5f97\u7a0d\u597d\u7684\u6027\u80fd\u548c\u66f4\u5c11\u7684\u5185\u5b58\u4f7f\u7528\u3002<\/p>\n<p>\u5f53\u4f60\u4f7f\u7528\u7b26\u53f7\u4f5c\u4e3a\u952e\u65f6\uff0c\u4e5f\u9700\u8981\u4f7f\u7528\u7b26\u53f7\u6765\u68c0\u7d22\u503c\uff1a<\/p>\n<pre class=\"post-pre\"><code>print user<span class=\"token punctuation\">[<\/span><span class=\"token symbol\">:first_name<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># \"Sammy\"<\/span>\r\nprint user<span class=\"token punctuation\">[<\/span><span class=\"token symbol\">:last_name<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token comment\"># \"Shark\"<\/span>\r\n<\/code><\/pre>\n<p>\u5728\u5b9a\u4e49\u54c8\u5e0c\u65f6\uff0c\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7a0d\u5fae\u4e0d\u540c\u7684\u8bed\u6cd5\uff1a<\/p>\n<pre class=\"post-pre\"><code>user <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token symbol\">first_name<\/span><span class=\"token operator\">:<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Sammy\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token symbol\">last_name<\/span><span class=\"token operator\">:<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Shark\"<\/span><\/span><span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u8bed\u6cd5\u4e0eJavaScript\u7b49\u5176\u4ed6\u8bed\u8a00\u4f7f\u7528\u7684\u8bed\u6cd5\u76f8\u4f3c\u3002\u8fd9\u79cd\u8bed\u6cd5\u5c06\u952e\u5b9a\u4e49\u4e3a\u7b26\u53f7\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>:first_name<\/code> \u548c <code>:last_name<\/code> \u6765\u8bbf\u95ee\u6761\u76ee\uff0c\u800c\u4e0d\u662f\u5b57\u7b26\u4e32 <code>\"first_name\"<\/code> \u548c <code>\"last_name\"<\/code>\u3002<\/p>\n<p>\u4f60\u5df2\u7ecf\u4e86\u89e3\u4e86\u51e0\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u770b Ruby \u662f\u5982\u4f55\u4e0e\u8fd9\u4e9b\u7c7b\u578b\u4e00\u8d77\u5de5\u4f5c\u7684\u3002<\/p>\n<h2>\u52a8\u6001\u7c7b\u578b<\/h2>\n<p><!-- \u8fd9\u662f\u6587\u7ae0\u300a\u7406\u89e3 Ruby \u4e2d\u7684\u6570\u636e\u7c7b\u578b\u300b\u7684\u7b2c5\u90e8\u5206\uff08\u51716\u90e8\u5206\uff09\u3002 --><\/p>\n<p>\u5728 Ruby \u4e2d\uff0c\u60a8\u5728\u8d4b\u503c\u4e4b\u524d\u65e0\u9700\u663e\u5f0f\u58f0\u660e\u6570\u636e\u7c7b\u578b\uff1b\u8d4b\u503c\u7684\u503c\u51b3\u5b9a\u4e86\u6570\u636e\u7c7b\u578b\u3002Ruby \u4f7f\u7528\u52a8\u6001\u7c7b\u578b\uff0c\u8fd9\u610f\u5473\u7740\u7c7b\u578b\u68c0\u67e5\u53d1\u751f\u5728\u8fd0\u884c\u65f6\u800c\u4e0d\u662f\u7f16\u8bd1\u65f6\uff0c\u8fd9\u4e0e\u4f7f\u7528\u9759\u6001\u7c7b\u578b\u8bed\u8a00\u4e0d\u540c\u3002Ruby \u6839\u636e\u53d8\u91cf\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u786e\u5b9a\u6570\u636e\u7c7b\u578b\u3002\u8fd9\u4e0e Python \u548c JavaScript \u4e2d\u7684\u6570\u636e\u7c7b\u578b\u5904\u7406\u65b9\u5f0f\u7c7b\u4f3c\u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u4e2d\u7684\u53d8\u91cf <code>t<\/code> \u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u4efb\u4f55\u53ef\u7528\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<pre class=\"post-pre\"><code>t = 42 <span class=\"token comment\"># t \u662f\u4e00\u4e2a Integer\uff08\u6574\u6570\uff09<\/span>\r\nt = <span class=\"token string\">\"Sammy\"<\/span> <span class=\"token comment\"># t \u662f\u4e00\u4e2a String\uff08\u5b57\u7b26\u4e32\uff09<\/span>\r\nt = :sammy <span class=\"token comment\"># t \u662f\u4e00\u4e2a Symbol\uff08\u7b26\u53f7\uff09<\/span>\r\nt = true <span class=\"token comment\"># t \u662f\u4e00\u4e2a boolean\uff08\u5e03\u5c14\u503c\uff0ctrue\uff09<\/span>\r\nt = nil <span class=\"token comment\"># t \u662f nil\uff08\u7a7a\u503c\uff09<\/span>\r\n<\/code><\/pre>\n<p>\u5728\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\u4e2d\uff0c\u60a8\u53ef\u4ee5\u91cd\u7528\u73b0\u6709\u53d8\u91cf\u6765\u4fdd\u5b58\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u5f53\u5c06\u6570\u636e\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\u65f6\uff0c\u8fd9\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u6709\u4e00\u6bb5\u4ee3\u7801\uff0c\u5b83\u4f1a\u8981\u6c42\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u6570\u503c\u3002<\/p>\n<pre class=\"post-pre\"><code>print <span class=\"token string\">\"Please enter the length of the room: \"<\/span>\r\nlength = gets.chop\r\n<\/code><\/pre>\n<p>\u4ece\u952e\u76d8\u83b7\u53d6\u7684\u6570\u636e\u59cb\u7ec8\u662f\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\u4e3a\u4e86\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\uff0c\u5fc5\u987b\u5c06 <code>length<\/code> \u53d8\u91cf\u7684\u6570\u636e\u8f6c\u6362\u4e3a\u6570\u5b57\u3002\u5728\u9759\u6001\u7c7b\u578b\u7684\u8bed\u8a00\u4e2d\uff0c\u5728\u5206\u914d\u503c\u4e4b\u524d\uff0c\u5fc5\u987b\u58f0\u660e\u53d8\u91cf\u7684\u6570\u636e\u7c7b\u578b\uff0c\u56e0\u6b64\u60a8\u9700\u8981\u4e00\u4e2a\u65b0\u53d8\u91cf\u6765\u4fdd\u5b58\u8f6c\u6362\u540e\u7684\u6570\u636e\u3002\u4f46\u662f\u5728 Ruby \u4e2d\uff0c\u7531\u4e8e\u5b83\u662f\u52a8\u6001\u7c7b\u578b\u7684\uff0c\u5982\u679c\u60a8\u613f\u610f\uff0c\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528 <code>length<\/code> \u53d8\u91cf\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># \u5c06\u503c\u8f6c\u6362\u4e3a Float\uff08\u6d6e\u70b9\u6570\uff09\u3002<\/span>\r\nlength = length.to_f\r\n<\/code><\/pre>\n<p><code>to_f<\/code> \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002Ruby \u8fd8\u63d0\u4f9b\u4e86 <code>to_i<\/code> \u65b9\u6cd5\uff0c\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\uff0c\u5927\u591a\u6570\u5bf9\u8c61\u4e5f\u53ef\u4ee5\u4f7f\u7528 <code>to_s<\/code> \u65b9\u6cd5\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<pre class=\"post-pre\"><code>42.to_s <span class=\"token comment\"># \"42\"<\/span>\r\n(42.5).to_s <span class=\"token comment\"># \"42.5\"<\/span>\r\n[<span class=\"token string\">\"Sammy\"<\/span>, <span class=\"token string\">\"Shark\"<\/span>].to_s <span class=\"token comment\"># \"[\\\"Sammy\\\", \\\"Shark\\\"]\"<\/span>\r\n<\/code><\/pre>\n<p>Ruby \u662f\u4e00\u79cd\u52a8\u6001\u7c7b\u578b\u8bed\u8a00\uff0c\u4f46\u5b83\u4e0d\u5141\u8bb8\u5728\u4e0d\u5c06\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u8f6c\u6362\u4e3a\u76f8\u540c\u7c7b\u578b\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u5bfc\u81f4\u9519\u8bef\uff1a<\/p>\n<pre class=\"post-pre\"><code>print 5 + <span class=\"token string\">\"5\"<\/span>\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>TypeError: String can't be coerced into Integer\r\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4e5f\u4f1a\u51fa\u73b0\u540c\u6837\u7684\u95ee\u9898\u3002<\/p>\n<pre class=\"post-pre\"><code>print <span class=\"token string\">\"5\"<\/span> + 5\r\n<\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>\n<pre class=\"post-pre\"><code>TypeError: no implicit conversion of Integer into String\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u60f3\u5c06\u6570\u5b57\u76f8\u52a0\u5f97\u5230 10\uff0c\u9700\u8981\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u3002\u5982\u679c\u4f60\u60f3\u5c06\u5b83\u4eec\u8fde\u63a5\u8d77\u6765\u5f97\u5230 &#8220;55&#8221;\uff0c\u5219\u9700\u8981\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u52a8\u6001\u7c7b\u578b\u63d0\u4f9b\u4e86\u7075\u6d3b\u6027\uff0c\u4f46\u5176\u7f3a\u70b9\u662f\u60a8\u4e0d\u80fd\u786e\u5207\u5730\u77e5\u9053\u6b63\u5728\u4f7f\u7528\u54ea\u79cd\u7c7b\u578b\u7684\u6570\u636e\uff0c\u56e0\u4e3a\u53d8\u91cf\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u53ef\u7528\u7684\u7c7b\u578b\u3002Ruby \u63d0\u4f9b\u4e86\u8bc6\u522b\u6570\u636e\u7c7b\u578b\u7684\u65b9\u6cd5\u3002<\/p>\n<h2>\u8bc6\u522b\u6570\u636e\u7c7b\u578b<\/h2>\n<p>\u8fd9\u662f\u6587\u7ae0\u300a\u7406\u89e3 Ruby \u4e2d\u7684\u6570\u636e\u7c7b\u578b\u300b\u7684\u7b2c6\u90e8\u5206\uff08\u51716\u90e8\u5206\uff09\u3002<\/p>\n<p>\u5728 Ruby \u4e2d\uff0c\u51e0\u4e4e\u6240\u6709\u4e1c\u897f\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u6570\u7ec4\u3001\u7b26\u53f7\u548c\u54c8\u5e0c\u90fd\u662f Ruby \u5bf9\u8c61\uff0c\u5e76\u4e14\u5b83\u4eec\u90fd\u6709\u4e00\u4e2a\u540d\u4e3a <code>class<\/code> \u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u544a\u8bc9\u4f60\u5b83\u4eec\u7684\u7c7b\u578b\u3002\u5373\u4f7f\u5e03\u5c14\u503c <code>true<\/code> \u548c <code>false<\/code>\uff0c\u4ee5\u53ca\u7a7a\u503c <code>nil<\/code>\uff0c\u90fd\u662f\u5bf9\u8c61\u3002\u81ea\u5df1\u8bd5\u8bd5\u770b\u5427\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"token number\">42.<\/span><span class=\"token keyword\">class<\/span> <span class=\"token comment\"># Integer<\/span>\r\n<span class=\"token punctuation\">(<\/span><span class=\"token number\">42.2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span> <span class=\"token comment\"># Float<\/span>\r\n<span class=\"token punctuation\">[<\/span><span class=\"token string-literal\"><span class=\"token string\">\"Sammy\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Shark\"<\/span><\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span> <span class=\"token comment\"># Array<\/span>\r\n<span class=\"token boolean\">true<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span> <span class=\"token comment\"># TrueClass<\/span>\r\n<span class=\"token keyword\">nil<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span> <span class=\"token comment\"># NilClass<\/span>\r\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>kind_of?<\/code> \u65b9\u6cd5\u6765\u9a8c\u8bc1\u7279\u5b9a\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"post-pre\"><code><span class=\"token number\">42.<\/span>kind_of<span class=\"token operator\">?<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">Integer<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># true<\/span>\r\n<\/code><\/pre>\n<p>\u5f53\u4f60\u6709\u4e00\u4e2a\u53d8\u91cf\u5e76\u4e14\u60f3\u786e\u5b9a\u5b83\u7684\u7c7b\u578b\u65f6\uff0c\u8fd9\u7279\u522b\u6709\u7528\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># \u5728\u4ee3\u7801\u7684\u67d0\u4e2a\u5730\u65b9...<\/span>\r\nsharks <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string-literal\"><span class=\"token string\">\"Hammerhead\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Tiger\"<\/span><\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-literal\"><span class=\"token string\">\"Great White\"<\/span><\/span><span class=\"token punctuation\">]<\/span>\r\n<span class=\"token operator\">...<\/span>\r\n<span class=\"token comment\"># \u5728\u5176\u4ed6\u5730\u65b9...<\/span>\r\n\r\nsharks<span class=\"token punctuation\">.<\/span>kind_of<span class=\"token operator\">?<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">Hash<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># false<\/span>\r\nsharks<span class=\"token punctuation\">.<\/span>kind_of<span class=\"token operator\">?<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">Array<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># true<\/span>\r\n<\/code><\/pre>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u9a8c\u8bc1\u6765\u81ea\u5916\u90e8\u6e90\u7684\u6570\u636e\u662f\u5426\u6b63\u786e\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"token keyword\">if<\/span> data<span class=\"token punctuation\">.<\/span>kind_of<span class=\"token operator\">?<\/span> <span class=\"token builtin\">String<\/span>\r\ndata <span class=\"token operator\">=<\/span> data<span class=\"token punctuation\">.<\/span>to_f\r\n<span class=\"token keyword\">end<\/span>\r\n<\/code><\/pre>\n<p>Ruby \u8fd8\u63d0\u4f9b\u4e86 <code>is_a?<\/code> \u65b9\u6cd5\uff0c\u5b83\u4e0e <code>kind_of?<\/code> \u65b9\u6cd5\u7684\u529f\u80fd\u76f8\u540c\uff0c\u4f46\u5bf9\u4e8e\u4e00\u4e9b\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u53ef\u80fd\u66f4\u5bb9\u6613\u9605\u8bfb\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"token keyword\">if<\/span> data<span class=\"token punctuation\">.<\/span>is_a<span class=\"token operator\">?<\/span> <span class=\"token builtin\">String<\/span>\r\ndata <span class=\"token operator\">=<\/span> data<span class=\"token punctuation\">.<\/span>to_f\r\n<span class=\"token keyword\">end<\/span>\r\n<\/code><\/pre>\n<p>\u4f7f\u7528 <code>class<\/code>\u3001<code>kind_of?<\/code> \u548c <code>is_a?<\/code> \u53ef\u4ee5\u5e2e\u52a9\u4f60\u786e\u4fdd\u4f60\u6b63\u5728\u4f7f\u7528\u6b63\u786e\u7c7b\u578b\u7684\u6570\u636e\u3002\u968f\u7740\u4f60\u5bf9 Ruby \u7684\u4e86\u89e3\u8d8a\u591a\uff0c\u4f60\u4f1a\u53d1\u73b0\u5176\u4ed6\u5904\u7406\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u800c\u4e0d\u9700\u8981\u660e\u786e\u68c0\u67e5\u6570\u636e\u7684\u7c7b\u578b\u3002<\/p>\n<h2>\u7ed3\u8bba<\/h2>\n<p>\u5728\u4f60\u7684 Ruby \u7a0b\u5e8f\u4e2d\uff0c\u4f60\u5c06\u4f7f\u7528\u5f88\u591a\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u73b0\u5728\u4f60\u5bf9 Ruby \u7a0b\u5e8f\u4e2d\u4e3b\u8981\u7684\u6570\u636e\u7c7b\u578b\u6709\u4e86\u66f4\u597d\u7684\u7406\u89e3\u3002<\/p>\n<p>\u8bf7\u9605\u8bfb\u8fd9\u4e9b\u6559\u7a0b\uff0c\u7ee7\u7eed\u63a2\u7d22 Ruby \u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<ul class=\"post-ul\">\n<li><a href=\"#\">\u5982\u4f55\u5728 Ruby \u4e2d\u4f7f\u7528\u5b57\u7b26\u4e32<\/a><\/li>\n<li><a href=\"#\">\u5982\u4f55\u5728 Ruby \u4e2d\u4f7f\u7528\u6570\u7ec4<\/a><\/li>\n<li><a href=\"#\">\u5982\u4f55\u5728 Ruby \u4e2d\u8f6c\u6362\u6570\u636e\u7c7b\u578b<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u5f53\u4f60\u7f16\u5199\u7a0b\u5e8f\u65f6\uff0c\u4f60\u9700\u8981\u4f7f\u7528\u6570\u636e\u7c7b\u578b\u6765\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7c7b\u3002\u6570\u636e\u7c7b\u578b\u544a\u8bc9\u8ba1\u7b97\u673a\u5982\u4f55\u5904\u7406\u7a0b\u5e8f\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u51b3\u5b9a\u4e86\u4f60\u53ef [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[258,316,317,314,315],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ruby","tag-316","tag-317","tag-314","tag-315"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u672c\u6559\u7a0b\u6df1\u5165\u63a2\u8ba8Ruby\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u3001\u6570\u7ec4\u3001\u54c8\u5e0c\u7b49\u3002\u901a\u8fc7\u5b9e\u4f8b\u89e3\u6790\u5176\u7279\u6027\u3001\u7528\u6cd5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u52a9\u60a8\u6253\u4e0b\u575a\u5b9e\u7684Ruby\u7f16\u7a0b\u57fa\u7840\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u7406\u89e3-ruby-\u4e2d\u7684\u6570\u636e\u7c7b\u578b\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6559\u7a0b\u6df1\u5165\u63a2\u8ba8Ruby\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u3001\u6570\u7ec4\u3001\u54c8\u5e0c\u7b49\u3002\u901a\u8fc7\u5b9e\u4f8b\u89e3\u6790\u5176\u7279\u6027\u3001\u7528\u6cd5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u52a9\u60a8\u6253\u4e0b\u575a\u5b9e\u7684Ruby\u7f16\u7a0b\u57fa\u7840\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u7406\u89e3-ruby-\u4e2d\u7684\u6570\u636e\u7c7b\u578b\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-09T00:52:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T13:46:32+00:00\" \/>\n<meta name=\"author\" content=\"\u6e05, \u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u5b87\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/\",\"name\":\"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-05-09T00:52:48+00:00\",\"dateModified\":\"2025-07-31T13:46:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"description\":\"\u672c\u6559\u7a0b\u6df1\u5165\u63a2\u8ba8Ruby\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u3001\u6570\u7ec4\u3001\u54c8\u5e0c\u7b49\u3002\u901a\u8fc7\u5b9e\u4f8b\u89e3\u6790\u5176\u7279\u6027\u3001\u7528\u6cd5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u52a9\u60a8\u6253\u4e0b\u575a\u5b9e\u7684Ruby\u7f16\u7a0b\u57fa\u7840\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\",\"name\":\"\u6e05, \u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud","description":"\u672c\u6559\u7a0b\u6df1\u5165\u63a2\u8ba8Ruby\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u3001\u6570\u7ec4\u3001\u54c8\u5e0c\u7b49\u3002\u901a\u8fc7\u5b9e\u4f8b\u89e3\u6790\u5176\u7279\u6027\u3001\u7528\u6cd5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u52a9\u60a8\u6253\u4e0b\u575a\u5b9e\u7684Ruby\u7f16\u7a0b\u57fa\u7840\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u7406\u89e3-ruby-\u4e2d\u7684\u6570\u636e\u7c7b\u578b\/","og_locale":"zh_CN","og_type":"article","og_title":"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528","og_description":"\u672c\u6559\u7a0b\u6df1\u5165\u63a2\u8ba8Ruby\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u3001\u6570\u7ec4\u3001\u54c8\u5e0c\u7b49\u3002\u901a\u8fc7\u5b9e\u4f8b\u89e3\u6790\u5176\u7279\u6027\u3001\u7528\u6cd5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u52a9\u60a8\u6253\u4e0b\u575a\u5b9e\u7684Ruby\u7f16\u7a0b\u57fa\u7840\u3002","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u7406\u89e3-ruby-\u4e2d\u7684\u6570\u636e\u7c7b\u578b\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-05-09T00:52:48+00:00","article_modified_time":"2025-07-31T13:46:32+00:00","author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/","name":"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-05-09T00:52:48+00:00","dateModified":"2025-07-31T13:46:32+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"description":"\u672c\u6559\u7a0b\u6df1\u5165\u63a2\u8ba8Ruby\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u5404\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u3001\u6570\u7ec4\u3001\u54c8\u5e0c\u7b49\u3002\u901a\u8fc7\u5b9e\u4f8b\u89e3\u6790\u5176\u7279\u6027\u3001\u7528\u6cd5\u53ca\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528\uff0c\u52a9\u60a8\u6253\u4e0b\u575a\u5b9e\u7684Ruby\u7f16\u7a0b\u57fa\u7840\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u6df1\u5165\u7406\u89e3Ruby\u6570\u636e\u7c7b\u578b\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e","name":"\u6e05, \u5b87","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","caption":"\u6e05, \u5b87"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e7%90%86%e8%a7%a3-ruby-%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":3,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":109488,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions\/109488"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}