{"id":4915,"date":"2013-12-12T07:27:12","date_gmt":"2013-12-11T22:27:12","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=4915"},"modified":"2013-12-12T07:27:12","modified_gmt":"2013-12-11T22:27:12","slug":"ruby-%e5%9f%ba%e6%9c%ac%e3%81%be%e3%81%a8%e3%82%81","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=4915","title":{"rendered":"Ruby \u57fa\u672c\u307e\u3068\u3081"},"content":{"rendered":"<p>\u3056\u3063\u3068Ruby\u306b\u95a2\u3059\u308b\u57fa\u790e\u7684\u306a\u90e8\u5206\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h4>Ruby\u57fa\u672c<\/h4>\n<h5>ruby\u5b9f\u884c<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ruby \u30d5\u30a1\u30a4\u30eb\u540d<\/pre>\n<\/p>\n<h5>\u00a0irb<\/h5>\n<p><strong>irb(Interactive Ruby)\u8d77\u52d5<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">irb<\/pre>\n<\/p>\n<p><strong>irb(Interactive Ruby)\u7d42\u4e86<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">exit<\/pre>\n<\/p>\n<h4>\u8868\u793a\u30e1\u30bd\u30c3\u30c9<\/h4>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">print <\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">puts<\/pre>\n<\/p>\n<h5>\u6570\u5024\u3001\u6587\u5b57\u5217\u5909\u63db<\/h5>\n<p><strong>to string\uff08\u6587\u5b57\u5217\u3078\uff09<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.to_s<\/pre>\n<p><strong>to integer \uff08\u6570\u5024\u3078\uff09<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.to_i<\/pre>\n<p><strong>to flort\uff08\u6d6e\u52d5\u5c0f\u6570\u70b9\u3078\uff09<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.to_f<\/pre>\n<\/p>\n<h4>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h4>\n<p><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30af\u30e9\u30b9\u3092\u8abf\u3079\u308b<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.class<\/pre>\n<p><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b9\u30fc\u30d1\u30fc\u30af\u30e9\u30b9\u3092\u8abf\u3079\u308b\u00a0<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.superclass<\/pre>\n<\/p>\n<p><strong>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u8abf\u3079\u308b<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.instance_of?(String)<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.instance_of?(Fixnum)<\/pre>\n<\/p>\n<p><strong>\u7a7a\u304b\u3069\u3046\u304b\u3092\u8abf\u3079\u308b\u00a0<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.empty?<\/pre>\n<\/p>\n<p><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8ID\u3092\u8abf\u3079\u308b<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.object_id<\/pre>\n<\/p>\n<p><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30b3\u30d4\u30fc<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.clone<\/pre>\n<\/p>\n<p><strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8ID\u304c\u540c\u3058\u304b\u00a0<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.equal?<\/pre>\n<\/p>\n<p><strong>\u4e2d\u8eab\u3092\u6bd4\u8f03<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"> == <\/pre>\n<\/p>\n<h4>Ruby\u306e\u5909\u6570<\/h4>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570<\/td>\n<td>$foo<\/td>\n<\/tr>\n<tr>\n<td>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570<\/td>\n<td>@foo<\/td>\n<\/tr>\n<tr>\n<td>\u30af\u30e9\u30b9\u5909\u6570<\/td>\n<td>@@foo<\/td>\n<\/tr>\n<tr>\n<td>\u30ed\u30fc\u30ab\u30eb\u5909\u6570<\/td>\n<td>foo<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>ruby\u306e\u4e88\u7d04\u8a9e<\/h5>\n<table style=\"width: 100%;\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\">BEGIN<\/td>\n<td valign=\"top\">END<\/td>\n<td valign=\"top\">alias<\/td>\n<td valign=\"top\">and<\/td>\n<td valign=\"top\">begin<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">break<\/td>\n<td valign=\"top\">case<\/td>\n<td valign=\"top\">class<\/td>\n<td valign=\"top\">def<\/td>\n<td valign=\"top\">defined?<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">do<\/td>\n<td valign=\"top\">else<\/td>\n<td valign=\"top\">elseif<\/td>\n<td valign=\"top\">end<\/td>\n<td valign=\"top\">ensure<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">false<\/td>\n<td valign=\"top\">for<\/td>\n<td valign=\"top\">if<\/td>\n<td valign=\"top\">in<\/td>\n<td valign=\"top\">module<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">next<\/td>\n<td valign=\"top\">nil<\/td>\n<td valign=\"top\">not<\/td>\n<td valign=\"top\">or<\/td>\n<td valign=\"top\">redo<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">rescue<\/td>\n<td valign=\"top\">retry<\/td>\n<td valign=\"top\">return<\/td>\n<td valign=\"top\">self<\/td>\n<td valign=\"top\">super<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">then<\/td>\n<td valign=\"top\">true<\/td>\n<td valign=\"top\">undef<\/td>\n<td valign=\"top\">unless<\/td>\n<td valign=\"top\">until<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">when<\/td>\n<td valign=\"top\">while<\/td>\n<td valign=\"top\">yield<\/td>\n<td valign=\"top\"><\/td>\n<td valign=\"top\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5b9a\u6570\u306f\u5168\u3066\u5927\u6587\u5b57<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ADMIN<\/pre>\n<\/p>\n<h4>\u5236\u5fa1\u69cb\u9020<\/h4>\n<h5>if\u6587<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">if \u6761\u4ef6 then\r\n\u00a0 \u6761\u4ef6\u304c\u771f\u306e\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\nend<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">if \u6761\u4ef6 then\r\n\u00a0   \u6761\u4ef6\u304c\u771f\u306e\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\n  else\r\n  \u00a0 \u6761\u4ef6\u304c\u507d\u306e\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\nend <\/pre>\n<\/p>\n<h5>unless\u6587<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">unless \u6761\u4ef6 then\r\n\u00a0   \u6761\u4ef6\u304c\u507d\u306e\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\n  else\r\n  \u00a0 \u6761\u4ef6\u304c\u771f\u306e\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\nend<\/pre>\n<\/p>\n<p>if \u6761\u4ef61 &amp;&amp; \u6761\u4ef62 then<\/p>\n<p>\u00a0\u6761\u4ef6\u304c\u771f\u306e\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406<\/p>\n<p>end<\/p>\n<h5>case\u6587<\/h5>\n<p><strong>case \u6bd4\u8f03\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">when \u50241 then\r\n \u00a0  \u50241\u3068\u4e00\u81f4\u3057\u305f\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\n  when \u50242 then\r\n    \u50242\u3068\u4e00\u81f4\u3057\u305f\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\n  when \u50243 then\r\n   \u00a0\u50243\u3068\u4e00\u81f4\u3057\u305f\u6642\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\n  else\r\n    \u3069\u306e\u5024\u306b\u3082\u4e00\u81f4\u3057\u306a\u3044\u3068\u304d\u306b\u5b9f\u884c\u3059\u308b\u51e6\u7406\r\nend<\/pre>\n<\/p>\n<h5>\u7e70\u308a\u8fd4\u3057\u51e6\u7406<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">while\u6587\r\n  while \u6761\u4ef6 do\r\n\u00a0 \u6761\u4ef6\u304c\u201d\u771f\u201d\u306e\u6642\u306b\u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<\/p>\n<h5>sleep<\/h5>\n<p>\u6307\u5b9a\u6642\u9593\u5f85\u6a5f<\/p>\n<\/p>\n<h5>until\u6587<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">until \u6761\u4ef6 do\r\n\u00a0 \u6761\u4ef6\u304c\u201d\u507d\u201d\u306e\u6642\u306b\u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<h5>for\u6587<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">for \u5909\u6570 in \u30aa\u30d6\u30b8\u30a7\u30af\u30c8 do\r\n  \u7e70\u308a\u8fd4\u3057\u51e6\u7406\r\nend<\/pre>\n<\/p>\n<h5>times\u30e1\u30bd\u30c3\u30c9 \u3067\u6307\u5b9a\u53ef\u6570\u7e70\u308a\u8fd4\u3057<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6574\u6570.times do |\u5909\u6570|\r\n\u00a0 \u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<p><strong>times\u30e1\u30bd\u30c3\u30c9\u4ed6\u306e\u8a18\u8ff0<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6574\u6570.times { |\u5909\u6570|\r\n\u00a0 \u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\n}<\/pre>\n<h5>upto,down to\u30e1\u30bd\u30c3\u30c9<\/h5>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>times<\/td>\n<td>integer<\/td>\n<\/tr>\n<tr>\n<td>upto<\/td>\n<td>integer<\/td>\n<\/tr>\n<tr>\n<td>downto<\/td>\n<td>integer<\/td>\n<\/tr>\n<tr>\n<td>step<\/td>\n<td>Numeric<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/p>\n<h5>upto\u30e1\u30bd\u30c3\u30c9<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6574\u6570.upto(max) do |\u5909\u6570|\r\n\u00a0 \u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<\/p>\n<h5>downto\u30e1\u30bd\u30c3\u30c9<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6574\u6570.downto(min) do |\u5909\u6570|\r\n\u00a0 \u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<h5>step\u30e1\u30bd\u30c3\u30c9<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6574\u6570.step(limit, step) do |\u5909\u6570|\r\n\u00a0 \u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<\/p>\n<h5>each\u30e1\u30bd\u30c3\u30c9<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8.each do |\u5909\u6570|\r\n\u00a0 \u7e70\u308a\u8fd4\u3059\u51e6\u7406\r\nend<\/pre>\n<h5>\u30eb\u30fc\u30d7\u7d42\u4e86<\/h5>\n<p>break<\/p>\n<\/p>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">dollar = 102\r\ni = 1\r\nloop {\r\n\u00a0 rate = i *\u00a0dollar\r\n\u00a0 if rate &gt;= 5000\r\n\u00a0 \u00a0 break\r\n\u00a0 end\r\n\u00a0 print i, \u201c$ ==&gt; \u201c,\u00a0&lt;span style=&quot;font-family: Arial, 'Arial New', '\uff2d\uff33 \uff30 \u30b4\u30b7\u30c3\u30af', sans-serif;&quot;&gt;rate&lt;\/span&gt;, \u201cYen\u00a5n&quot;&lt;\/p&gt;\r\n\u00a0 i = i + 1\r\n}<\/pre>\n<h4>ruby\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u306e ruby\u306e\u547c\u3073\u51fa\u3057<\/h4>\n<h5>win<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">#!C:\/ruby\/bin\/ruby<\/pre>\n<\/p>\n<h5>mac<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">#!\/usr\/bin\/ruby<\/pre>\n<\/p>\n<h5>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067\u5b9f\u884c<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$ .\/hoge.rb<\/pre>\n<\/p>\n<h5><strong>\u6587\u5b57\u30b3\u30fc\u30c9\u6307\u5b9a<\/strong><\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">#!\/usr\/bin\/ruby -Ks<\/pre>\n<\/p>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>EUC<\/td>\n<td>-Ke<\/td>\n<\/tr>\n<tr>\n<td>Shift-JIS<\/td>\n<td>-Ks<\/td>\n<\/tr>\n<tr>\n<td>UTF-8<\/td>\n<td>-Ku<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/p>\n<h5>\u5236\u5fa1\u6587\u5b57<\/h5>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>\u00a5b<\/td>\n<td>\u30d0\u30c3\u30af\u30b9\u30da\u30fc\u30b9<\/td>\n<\/tr>\n<tr>\n<td>\u00a5e<\/td>\n<td>\u30a8\u30b9\u30b1\u30fc\u30d7<\/td>\n<\/tr>\n<tr>\n<td>\u00a5f<\/td>\n<td>\u6539\u30da\u30fc\u30b8<\/td>\n<\/tr>\n<tr>\n<td>\u00a5n<\/td>\n<td>\u6539\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u00a5r<\/td>\n<td>\u5fa9\u5e30<\/td>\n<\/tr>\n<tr>\n<td>\u00a5s<\/td>\n<td>\u534a\u89d2\u30b9\u30da\u30fc\u30b9<\/td>\n<\/tr>\n<tr>\n<td>\u00a5t<\/td>\n<td>\u30bf\u30d6<\/td>\n<\/tr>\n<tr>\n<td>\u00a5\u00a5<\/td>\n<td>\u00a5<span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u6587\u5b57\u5217\u4e2d\u3067\u5909\u6570\u3001\u5f0f\u3092\u4f7f\u7528<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">#{ \u5909\u6570 }<\/pre>\n<\/p>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">who = \u201c\u305f\u304b\u3084\u307e\"\r\nprint \u201c\u3053\u3093\u306b\u3061\u306f\u3001\u201d, who, \u201d\u3055\u3093\u201d<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">who = \u201c\u305f\u304b\u3084\u307e\"\r\nprint \u201c\u3053\u3093\u306b\u3061\u306f\u3001#{who}\u3055\u3093\u201d<\/pre>\n<\/p>\n<p><strong>\u8a08\u7b97\u5f0f\u3082\u53ef\u80fd<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">print \u201c\u8a08\u7b97\uff1a20 \u00d7 20 = #{20*20}\u3067\u3059\u201d <\/pre>\n<\/p>\n<h4>\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c<\/h4>\n<h5>\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">File.open(\u201c\u30d5\u30a1\u30a4\u30eb\u540d\u201d, \u201c\u30e2\u30fc\u30c9\")<\/pre>\n<\/p>\n<p><strong>\u8aad\u307f\u8fbc\u307f\u306e\u307f<\/strong><\/p>\n<p>File.open(\u201cindex.txt\u201d, \u201cr&#8221;)<\/p>\n<\/p>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>r<\/td>\n<td>\u8aad\u307f\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>r+<\/td>\n<td>\u8aad\u307f\u8fbc\u307f\u3068\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>\u65b0\u898f\u306b\u4f5c\u6210\u3057\u3066\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>w+<\/td>\n<td>\u65b0\u898f\u306b\u4f5c\u6210\u3057\u3066\u8aad\u307f\u8fbc\u307f\u3068\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>a<\/td>\n<td>\u8ffd\u52a0\u3067\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>a+<\/td>\n<td>\u8ffd\u52a0\u3067\u8aad\u307f\u8fbc\u307f\u3068\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">f = File.open(\u201cindex.txt\")<\/pre>\n<\/p>\n<p><strong>\u307e\u3068\u3081\u3066\u8aad\u307f\u8fbc\u307f<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">f.read<\/pre>\n<\/p>\n<p><strong>\u6a19\u6e96\u51fa\u529b<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">print f.read<\/pre>\n<\/p>\n<p><strong>\u8aad\u307f\u8fbc\u307f\u5f8c\u306f\u9589\u3058\u308b<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">f.close<\/pre>\n<\/p>\n<h5>1\u884c\u305a\u3064\u8aad\u307f\u8fbc\u307f<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">f = File.open(\u201cindex.txt\u201d)\r\nf.each{|line|\r\n\u00a0 print line\r\n}\r\nf.close<\/pre>\n<h4>\u914d\u5217\u3068\u30cf\u30c3\u30b7\u30e5<\/h4>\n<h4>\u914d\u5217<\/h4>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">foo = &#x5B;]<\/pre>\n<\/p>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">#!\/usr\/bin\/ruby\r\narr = &#x5B;\u201cweb\u5e33\u201d, \u201ctakayama\u201d,\u201dboy\"]\r\nprint \u201c\u3053\u306e\u30b5\u30a4\u30c8\u306f\u201d, arr&#x5B;0], \u201c\u3067\u3059\u00a5n\u201d\r\nprint \u201c\u4f5c\u8005\u306f\u201d, arr&#x5B;1], \u201c\u3067\u00a5n\u201d\r\nprint \u00a0arr&#x5B;1], \u201c\u306f\u201d, arr&#x5B;2], \u201c\u3067\u3042\u308b\u00a5n\u201d <\/pre>\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">fruit = &#x5B;\u201c\u307f\u304b\u3093\u201d,\u201d\u308a\u3093\u3054\u201d,\u201d\u306a\u3057\u201d,\u201d\u3076\u3069\u3046\u201d,\u201d\u3082\u3082\"]\r\nputs\u00a0fruit\u00a0&#x5B;0..3]\r\nputs\u00a0fruit\u00a0&#x5B;1, 3] <\/pre>\n<h5>\u6570\u3092\u8abf\u3079\u308b<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">puts\u00a0fruit.size<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">puts\u00a0fruit.length<\/pre>\n<\/p>\n<h5>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5f15\u6570\u53d6\u5f97<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ARGV<\/pre>\n<\/p>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">sample.rb one two<\/pre>\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">#!\/usr\/bin\/ruby\r\n\r\n# 1\u301c3\u756a\u76ee\u306e\u5f15\u6570\u3092\u8868\u793a\r\nputs ARGV&#x5B;0]\r\nputs ARGV&#x5B;1]\r\nputs ARGV&#x5B;2]\u00a0<\/pre>\n<p><strong>\u5168\u3066\u306e\u5f15\u6570\u3092\u8868\u793a<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">puts ARGV\u00a0<\/pre>\n<\/p>\n<p><strong>\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3067\u306e\u8868\u793a<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ARGV .each{|arg|\r\n  puts arg\r\n  puts \u201c**************\"\r\n}\u00a0<\/pre>\n<\/p>\n<h5><strong>\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc<\/strong><\/h5>\n<p><strong>example<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">f1 = File.open(ARGV&#x5B;0])\r\nf2 = File.open(ARGV&#x5B;1], \u201cw\")\r\n\r\ndata = f1.read\r\nf2.print data\r\n\r\nf1.close\r\nf2.close\u00a0<\/pre>\n<\/p>\n<h4>\u30cf\u30c3\u30b7\u30e5<\/h4>\n<p><strong>\u9023\u60f3\u914d\u5217<\/strong><\/p>\n<p>\u30ad\u30fc\uff08key\uff09\u3068\u5024\uff08value\uff09<\/p>\n<p>\u30ad\u30fc =&gt; \u5024<\/p>\n<\/p>\n<p>animal = {<\/p>\n<p>\u00a0 \u201ccat\u201d =&gt; \u201c\u305f\u307e\u201d,<\/p>\n<p>\u00a0\u201cdog\u201d =&gt; \u201c\u307d\u3061\u201d,<\/p>\n<p>\u00a0\u201cbird\u201d =&gt; \u201c\u3068\u308a\u3093\u3069\u308b\u201d<\/p>\n<p>}<\/p>\n<\/p>\n<h5>key\u53d6\u5f97<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.keys<\/pre>\n<h5>value\u53d6\u5f97<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.values<\/pre>\n<\/p>\n<p><strong>\u30d5\u30a7\u30c3\u30c1\u3067\u53d6\u308a\u51fa\u3059\u4e8b\u3082\u53ef\u80fd<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.fetch<\/pre>\n<\/p>\n<p>each\u3067\u306e\u7e70\u308a\u8fd4\u3057\u3067\u306e\u53d6\u5f97<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">.each_key{|key|\r\n\u00a0 puts \u201c#{key}\"\r\n}<\/pre>\n<h5>\u914d\u5217\u306e\u30cf\u30c3\u30b7\u30e5<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">animal = {\r\n  \u201cdog\u201d =&gt; &#x5B;\u201c\u307d\u3061\u201d,\u201d\u3058\u308d\u3046\u201d,\u201d\u3054\u307e\u201d],\r\n  \u201ccat\u201d =&gt; &#x5B;\u201c\u305f\u307e\u201d,\u201d\u3054\u308d\u3046\u201d,\u201d\u3072\u306a\u201d]\r\n}<\/pre>\n<h5>\u30cf\u30c3\u30b7\u30e5\u306e\u914d\u5217<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">student\u00a0= &#x5B;\r\n  { \u201cno\u201d =&gt; 1, \u201cname\u201d =&gt; \u201c\u305f\u304b\u3084\u307e\u201d, \u201cblood\u201d =&gt; \u201cO\u201d},\r\n  { \u201cno\u201d =&gt; 1, \u201cname\u201d =&gt; \u201c\u305f\u306a\u304b\u201d, \u201cblood\u201d =&gt; \u201cA\u201d}\r\n] <\/pre>\n<h5>\u30cf\u30c3\u30b7\u30e5\u306e\u30cf\u30c3\u30b7\u30e5<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">band = {\r\n  \u201c1\u201d =&gt; {\u201cname\u201d =&gt; \u201c\u305f\u304b\u3084\u307e\u201d, \u201cpart\u201d =&gt; \u201cguitar\u201d},\r\n  \u201c2\u201d =&gt; {\u201cname\u201d =&gt; \u201c\u305f\u306a\u304b\u201d, \u201cpart\u201d =&gt; \u201cvocal\u201d},\r\n  \u201c3\u201d =&gt; {\u201cname\u201d =&gt; \u201c\u306a\u304b\u305f\u201d, \u201cpart\u201d =&gt; \u201cbass\u201d}\r\n}<\/pre>\n<\/p>\n<h4>\u6b63\u898f\u8868\u73fe<\/h4>\n<\/p>\n<p>\u30de\u30c3\u30c1\u3059\u308b\u304b\u306f~\uff08\u30c1\u30eb\u30c0\uff09\u3092\u7528\u3044\u3066\u5224\u5225<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6b63\u898f\u8868\u73fe\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 =~ \u6587\u5b57\u5217\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/pre>\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/^How\/ =~ \u201cHow are you?\u00a0&quot;\r\n=&gt; 0<\/pre>\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/sad\/ =~ \u201cI am sad.\u00a0&quot;\r\n=&gt; 5<\/pre>\n<h5>\u4e3b\u306a\u30e1\u30bf\u6587\u5b57<\/h5>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>.<\/td>\n<td>\u4efb\u610f\u306e1\u6587\u5b57\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>0\u56de\u4ee5\u4e0a\u306e\u7e70\u308a\u8fd4\u3057\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>1\u56de\u4ee5\u4e0a\u306e\u7e70\u308a\u8fd4\u3057\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>?<\/td>\n<td>0\u56de\u307e\u305f\u306f1\u56de\u306e\u7e70\u308a\u8fd4\u3057\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>{}<\/td>\n<td>\u6307\u5b9a\u3057\u305f\u7bc4\u56f2\u306e\u7e70\u308a\u8fd4\u3057\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>()<\/td>\n<td>\u30b0\u30eb\u30fc\u30d7<\/td>\n<\/tr>\n<tr>\n<td>[]<\/td>\n<td>\u6587\u5b57\u30af\u30e9\u30b9<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>\u884c\u982d\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>\u884c\u672b\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>|<\/td>\n<td>\u3044\u305a\u308c\u304b\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>{m}<\/td>\n<td>m\u56de\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>{m,}<\/td>\n<td>m\u56de\u4ee5\u4e0a\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<tr>\n<td>{m,n}<\/td>\n<td>m\u56de\u4ee5\u4e0a,n\u56de\u4ee5\u4e0b\u306b\u30de\u30c3\u30c1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u9078\u629e<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/apple|orange\/<\/pre>\n<p><strong>\u30b0\u30eb\u30fc\u30d7\u5316<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/(sing){2}\/ =~ &quot;singapplesongsingsingsong&quot;\r\n=&gt; 13<\/pre>\n<p><strong>\u5f8c\u65b9\u53c2\u7167<\/strong><\/p>\n<p>\u6b63\u898f\u8868\u73fe\u30b0\u30eb\u30fc\u30d7\u306b\u3088\u308b\u5f8c\u65b9\u53c2\u7167<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\/5(.)7(.)\/ =~ &quot;123456788&quot;\r\n=&gt; 4<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$1\r\n=&gt; &quot;6&quot;<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">$2\r\n=&gt; &quot;8&quot;<\/pre>\n<\/p>\n<h5>\u6587\u5b57\u30af\u30e9\u30b9\u306e\u4e3b\u306a\u7565\u8a18\u6cd5<\/h5>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>\u00a5w<\/td>\n<td>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u3068\u6570\u5b57<\/td>\n<\/tr>\n<tr>\n<td>\u00a5W<\/td>\n<td>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u3068\u6570\u5b57\u4ee5\u5916<\/td>\n<\/tr>\n<tr>\n<td>\u00a5s<\/td>\n<td>\u7a7a\u767d\u6587\u5b57<\/td>\n<\/tr>\n<tr>\n<td>\u00a5S<\/td>\n<td>\u7a7a\u767d\u6587\u5b57\u4ee5\u5916<\/td>\n<\/tr>\n<tr>\n<td>\u00a5d<\/td>\n<td>\u6570\u5b57<\/td>\n<\/tr>\n<tr>\n<td>\u00a5D<\/td>\n<td>\u6570\u5b57\u4ee5\u5916<\/td>\n<\/tr>\n<tr>\n<td>\u00a5b<\/td>\n<td>\u5358\u8a9e\u306e\u5883\u754c<\/td>\n<\/tr>\n<tr>\n<td>\u00a5B<\/td>\n<td>\u5358\u8a9e\u306e\u5883\u754c\u4ee5\u5916<\/td>\n<\/tr>\n<tr>\n<td>\u00a5A<\/td>\n<td>\u6587\u5b57\u5217\u306e\u6700\u521d<\/td>\n<\/tr>\n<tr>\n<td>\u00a5Z<\/td>\n<td>\u6587\u5b57\u5217\u306e\u6700\u5f8c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u65e5\u672c\u8a9e\u306e\u6b63\u898f\u8868\u73fe<\/h5>\n<table border=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td>s<\/td>\n<td>Shift-JIS<\/td>\n<\/tr>\n<tr>\n<td>e<\/td>\n<td>EUC-JP<\/td>\n<\/tr>\n<tr>\n<td>u<\/td>\n<td>UTF-8<\/td>\n<\/tr>\n<tr>\n<td>n<\/td>\n<td>\u6587\u5b57\u30b3\u30fc\u30c9\u306a\u3057<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u6587\u5b57\u3092\u7f6e\u63db<\/h5>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\u6587\u5b57\u5217.sub(\/\u30d1\u30bf\u30fc\u30f3\/,\u201d\u7f6e\u63db\u6587\u5b57\u5217\")<\/pre>\n<\/p>\n<p>\u3059\u3079\u3066\u7f6e\u63db<\/p>\n<p><strong>.gsub<\/strong><\/p>\n<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">puts str.gsub(\/\u30a6\u30a7\u30d6\/s,\u201dWeb\")<\/pre>\n<\/p>\n<h4>\u30e1\u30bd\u30c3\u30c9<\/h4>\n<p>\u30e1\u30bd\u30c3\u30c9\u5b9a\u7fa9<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">def \u30e1\u30bd\u30c3\u30c9\u540d\r\n \u00a0\u51e6\u7406\r\n  ...\r\nend<\/pre>\n<\/p>\n<p><strong>\u5f15\u6570<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">def hello who\r\n\u00a0 \u51e6\u7406..\r\nend<\/pre>\n<p>\u307e\u305f\u306f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">def hello(who)\r\n\u00a0 \u51e6\u7406..\r\nend <\/pre>\n<p><strong>\u30af\u30e9\u30b9\u5b9a\u7fa9<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">class \u30af\u30e9\u30b9\u540d\r\n \u00a0\u30af\u30e9\u30b9\u306e\u5b9a\u7fa9...\r\nendf<\/pre>\n<h4>\u30e2\u30b8\u30e5\u30fc\u30eb<\/h4>\n<p>\u30e2\u30b8\u30e5\u30fc\u30eb\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u308c\u306a\u3044 include\u3057\u3066\u306e\u5229\u7528\u3068\u306a\u308b\u3002\uff08 Mix-in\uff09<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">module \u30e2\u30b8\u30e5\u30fc\u30eb\u540d\r\n\u00a0 \u30e2\u30b8\u30e5\u30fc\u30eb\u5b9a\u7fa9\r\nend<\/pre>\n<p><strong>\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8aad\u307f\u8fbc\u307f<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">require \u201chogege\"<\/pre>\n<p>\u4ee5\u4e0a\u306b\u306a\u308a\u307e\u3059\u30fc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3056\u3063\u3068Ruby\u306b\u95a2\u3059\u308b\u57fa\u790e\u7684\u306a\u90e8\u5206\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002 Ruby\u57fa\u672c ruby\u5b9f\u884c ruby \u30d5\u30a1\u30a4\u30eb\u540d \u00a0irb irb(Interactive Ruby)\u8d77\u52d5 irb irb(Interactive Ruby)\u7d42\u4e86  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[155],"tags":[183,44,45],"class_list":["post-4915","post","type-post","status-publish","format-standard","hentry","category-ruby","tag-ruby","tag-web"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4915"}],"version-history":[{"count":9,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4915\/revisions"}],"predecessor-version":[{"id":4924,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/4915\/revisions\/4924"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}