{"id":4957,"date":"2015-01-15T10:58:52","date_gmt":"2015-01-15T01:58:52","guid":{"rendered":"http:\/\/www.vincentina.net\/?p=4957"},"modified":"2021-12-22T22:53:23","modified_gmt":"2021-12-22T13:53:23","slug":"ruby%e3%81%ae%e5%8b%89%e5%bc%b7%e3%82%92%e5%88%9d%e3%82%81%e3%81%a6%e6%b0%97%e3%81%ab%e3%81%aa%e3%81%a3%e3%81%9f%e3%81%a8%e3%81%93%e3%83%91%e3%83%bc%e3%83%88%ef%bc%92","status":"publish","type":"post","link":"https:\/\/www.vincentina.net\/?p=4957","title":{"rendered":"Ruby \u306e\u52c9\u5f37\u3092\u521d\u3081\u3066\u6c17\u306b\u306a\u3063\u305f\u3068\u3053\u308d\u3092\u3042\u308c\u3053\u308c 2"},"content":{"rendered":"<p>Ruby\u306e\u52c9\u5f37\u3092\u521d\u3081\u3066\u304b\u3089\u3001\u305f\u3060\u3044\u307e\u30d1\u30fc\u30d5\u30a7\u30af\u30c8Ruby\u3068\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9eRuby\u3068\u3044\u3046\u66f8\u7c4d\u3092\u4e26\u884c\u3057\u3066\u9032\u3081\u308b\u30ab\u30cb\u30d0\u30b5\u30df\u52c9\u5f37\u4e2d\u3002\u3053\u306e2\u518a\u3092\u540c\u6642\u306b\u9032\u3081\u3066\u307f\u3066\u6c17\u306b\u306a\u3063\u305f\u3068\u3053\u3084\u3089\u3092\u3042\u308c\u3053\u308c\u30c4\u30e9\u30c4\u30e9\u3068\u66f8\u3044\u3066\u307f\u308b\u30d1\u30fc\u30c82<\/p>\n<h2>\u30fb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u201d\u30dd\u30a4\u30f3\u30bf\u306e\u3088\u3046\u306a\u3082\u306e\u201d\u3089\u3057\u3044\u3051\u308c\u3069<\/h2>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3064\u3044\u3066\u7406\u89e3\u3067\u304d\u3066\u3044\u306a\u3044\u72b6\u614b\u3060\u3068\u8aac\u660e\u6587\u306e\u305d\u306e\u307e\u3093\u307e\u3001\u201d<strong>\u30dd\u30a4\u30f3\u30bf\u306e\u3088\u3046\u306a\u3082\u306e<\/strong>\u201d\u3068\u3057\u304b\u89e3\u91c8\u304c\u3067\u304d\u306b\u3083\u3044\u3002<br \/>\n\u300c<strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u53c2\u7167<\/strong>\u300d\u3068\u3044\u3046\u5358\u5143\u306e\u8aac\u660e\u3082\u3042\u3063\u305f\u3051\u308c\u3069\u3001\u3053\u306e\u7d50\u679c\u3092\u898b\u305f\u65b9\u304c\u5206\u304b\u308a\u3084\u3059\u3044\u6c17\u304c\u3059\u30fc\u3002\u305f\u3060\u3001\u3053\u308c\u3092\u898b\u308b\u3068\u201d<strong>\u306e\u3088\u3046\u306a\u3082\u306e<\/strong>\u201d\u3068\u3044\u3046\u304b\u3001\u201d<strong>\u3053\u308c\u306f\u30dd\u30a4\u30f3\u30bf\u3060<\/strong>\u201d\u3068\u601d\u3063\u3061\u307e\u3044\u307e\u3059\u3002<br \/>\n\u30dd\u30a4\u30f3\u30bf\u306e\u3053\u3068\u3092\u3069\u308c\u3060\u3051\u7406\u89e3\u3057\u3066\u3044\u308b\u306e\u304b\u306f\u7f6e\u3044\u3068\u3044\u3066\u306d\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">irb(main):001:0&gt; a\u00a0 = &quot;Ruby&quot;\r\n=&gt; &quot;Ruby&quot;\r\nirb(main):002:0&gt; b = c = &quot;Ruby&quot;\r\n=&gt; &quot;Ruby&quot;\r\nirb(main):003:0&gt; a.equal?(b)\r\n=&gt; false\r\nirb(main):004:0&gt; b.equal?(c)\r\n=&gt; true\r\nirb(main):008:0&gt; a == b\r\n=&gt; true<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30fb0.0\/0.0 \u306f\u6570\u5b57\u3067\u306f\u306a\u3044\u3051\u308c\u3069<\/h2>\n<p>\u6570\u5b57\u3068\u307f\u306a\u3059\u3068 <strong>0 \u3060\u306e\u306a<\/strong>\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">irb(main):003:0&gt; num = 0.0\/0.0\r\n=&gt; NaN\r\nirb(main):004:0&gt; num\r\n=&gt; NaN\r\nirb(main):006:0&gt; a.to_i\r\n=&gt; 0\r\nirb(main):010:0&gt; a.to_f\r\n=&gt; 0.0<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30fb\u4f8b\u5916\u51e6\u7406\u304c\u521d\u898b\u3067\u306f\u5206\u304b\u308a\u306b\u304f\u3044\u305c<\/h2>\n<p>\u305d\u306e\u307e\u3093\u307e\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">#!\/home\/takeken\/.rbenv\/shims\/ruby\r\n\r\nbegin\r\n\u00a0 file = File.open('hoge.txt')\r\nrescue\r\n\u00a0 puts 'File\u304c\u307f\u3064\u304b\u308a\u307e\u305b\u306c'\r\nensure\r\n\u00a0 file.close if file\r\nend<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30fb\u4f8b\u5916\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3042\u308c\u3053\u308c<\/h2>\n<p>\u304a\u624b\u8efd\u3060\u3002\u4eca\u306e\u3068\u3053\u308d\u4f8b\u5916\u3092\u6d3b\u304b\u3057\u305f\u3082\u306e\u304c\u66f8\u3051\u3066\u3044\u306a\u3044\u306e\u3067\u4f7f\u308f\u306a\u3044\u3068\u3060\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\ne.class\r\n&#x5B;takeken@localhost]$ .\/hoge.rb\r\nError occurred (Errno::ENOENT)\r\ne.message\r\n&#x5B;takeken@localhost]$ .\/hoge.rb\r\nError occurred (No such file or directory @ rb_sysopen - hoge.txt)\r\ne.backtrace\r\n&#x5B;takeken@localhost]$ .\/hoge.rb\r\nError occurred (&#x5B;&quot;.\/hoge.rb:4:in `initialize'&quot;, &quot;.\/hoge.rb:4:in `open'&quot;, &quot;.\/hoge.rb:4:in `&lt;main&gt;'&quot;])\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30fb\u30ec\u30b7\u30fc\u30d0\u30fb\u5f15\u6570\u306a\u3057\u3067\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3068\u304d\u306f\u30ab\u30c3\u30b3\u3092\u7701\u7565\u3067\u304d\u306a\u3044<\/h2>\n<p>\u305d\u306e\u307e\u307e\u306e\u610f\u5473\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30fbUbuntu\u3068OSX\u306e\u9055\u3044<\/h2>\n<p>\u80cc\u666f\u304c\u3042\u3063\u3066\u3082\u30d5\u30a9\u30f3\u30c8\u304c\u898b\u3084\u3059\u3044\u306e\u306f\u6d41\u77f3\u3067\u3001\u8a2d\u5b9a\u3057\u3060\u3044\u3067\u306f\u4e21\u8005\u3068\u3082\u304b\u306a\u308a\u8fd1\u3065\u304f\u3068\u601d\u3046\u3051\u308c\u3069\u3001\u3084\u3063\u3071\u308a\u500b\u6027\u304c\u3042\u308b\u306e\u3067\u9055\u3044\u3092\u611f\u3058\u308b\u306a\u3041\u3002\u4eca\u306f\u3084\u3063\u3071OSX\u304c\u30a4\u30a4m9(^^)<\/p>\n<p>Ubuntu<\/p>\n<p><a href=\"http:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/nagatos1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/nagatos1-300x172.png\" alt=\"nagatos1\" width=\"300\" height=\"172\" class=\"alignnone size-medium wp-image-4960\" srcset=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/nagatos1-300x172.png 300w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/nagatos1-624x359.png 624w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/nagatos1.png 736w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><\/p>\n<p>Mac OSX<\/p>\n<p><a href=\"http:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/ss.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/ss-300x167.png\" alt=\"ss\" width=\"300\" height=\"167\" class=\"alignnone size-medium wp-image-4968\" srcset=\"https:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/ss-300x167.png 300w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/ss-624x348.png 624w, https:\/\/www.vincentina.net\/wp-content\/uploads\/2015\/01\/ss.png 1016w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u30fb\u30d6\u30ed\u30c3\u30af\u3068\u3057\u3066\u6e21\u3059<\/h2>\n<p>\u3053\u3046\u3044\u3046\u66f8\u304d\u65b9\u3082\u3067\u304d\u308b\u307f\u305f\u3044\u3067\u3001\u3053\u306e\u8fba\u306f\u3042\u3093\u307e\u308a\u6839\u8a70\u3081\u3066\u3084\u3063\u3061\u3083\u3046\u3068\u304a\u3044\u3089\u306e\u982d\u3060\u3068\u30d1\u30cb\u30c3\u30af\u3057\u305d\u3046\u3060\u304b\u3089\u3001\u3060\u3044\u305f\u3044\u3067\u6d41\u3057\u3066\u304a\u3053\u3046\u3068\u601d\u3046\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">#!\/home\/takeken\/.rbenv\/shims\/ruby\r\n\r\npeople = %w(Alice Bob Charlie)\r\nblock = Proc.new do |name|\r\n\u00a0 puts name\r\nend\r\npeople.each &amp;block\r\n\r\n&#x5B;takeken@localhost]$ .\/hoge.rb\r\nAlice\r\nBob\r\nCharlie<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30fbRequire\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u306fLOADED_FEATURES\u306b\u8ffd\u52a0\u3055\u308c\u308b<\/h2>\n<p>\u8abf\u3079\u3066\u307f\u305f\u3002\u306a\u308b\u307b\u3069\u3002<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">irb(main):001:0&gt; x = p $LOADED_FEATURES\r\n\r\nirb(main):002:0&gt; p x.last(1)\r\n&#x5B;&quot;\/home\/takeken\/.rbenv\/versions\/2.1.5\/lib\/ruby\/2.1.0\/rubygems\/dependency.rb&quot;]\r\n=&gt; &#x5B;&quot;\/home\/takeken\/.rbenv\/versions\/2.1.5\/lib\/ruby\/2.1.0\/rubygems\/dependency.rb&quot;]\r\n\r\nirb(main):003:0&gt; require 'json'\r\n=&gt; true\r\nirb(main):004:0&gt; p x.last(1)\r\n&#x5B;&quot;\/home\/takeken\/.rbenv\/versions\/2.1.5\/lib\/ruby\/2.1.0\/json.rb&quot;]\r\n=&gt; &#x5B;&quot;\/home\/takeken\/.rbenv\/versions\/2.1.5\/lib\/ruby\/2.1.0\/json.rb&quot;]<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u3068\u308a\u3042\u3048\u305a\u30d1\u30fc\u30c8\uff12\u306f\u3053\u3093\u306a\u304f\u3089\u3044\u3067\u7d42\u308f\u3063\u3068\u304d\u307e\u3059\u3002<\/p>\n<p>Mac\u306b\u306a\u3063\u305f\u304b\u3089\u3068\u3044\u3046\u8a33\u3067\u306f\u306a\u304f\u3001wowow\u3067\u305f\u307e\u305f\u307e\u30b9\u30c6\u30a3\u30fc\u30d6\u30fb\u30b8\u30e7\u30d6\u30ba\u3092\u3084\u3063\u3066\u3044\u305f\u306e\u3067\u9332\u3063\u3068\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3044\u308d\u3044\u308d\u8a70\u3081\u8fbc\u307f\u3059\u304e\u3066\u3044\u3066\u8a71\u304c\u3088\u304f\u5206\u304b\u3089\u306a\u3044\u3068\u3053\u308d\u304c\u7d50\u69cb\u591a\u304b\u3063\u305f\u306a\u3041\u2026w\u3000\u8272\u3005\u3068\u5727\u5012\u3055\u308c\u3066\u7d42\u308f\u3063\u305f\u611f\u3058\u3067\u3057\u305f\u3002<\/p>\n<p>\u307e\u3060\u8aad\u3093\u3067\u3044\u306a\u3044\u3051\u308c\u3069\u3001<span dir=\"auto\">\u30a6\u30a9\u30eb\u30bf\u30fc\u30fb\u30a2\u30a4\u30b6\u30c3\u30af\u30bd\u30f3<\/span>\u3055\u3093\u306e\u539f\u4f5c\u306e\u65b9\u304c\u3084\u3063\u3071\u308a\u9762\u767d\u3044\u306e\u3060\u308d\u3046\u306a\u3068\u601d\u3046\u3088\u3002<\/p>\n<p>\u4eca\u306e\u3068\u3053\u308d\u6620\u753b\u5316\u3001\u30a2\u30cb\u30e1\u5316\u3055\u308c\u305f\u4f5c\u54c1\u3067\u5c0f\u8aac\u3088\u308a\u3082\u9762\u767d\u304b\u3063\u305f\u4f8b\u304c\u306a\u3044 ( \u00b4\u0414`)\u03c3)\u0414`)<br \/>\n\u305d\u308c\u306f\u305d\u308c\u3067\u9762\u767d\u3044\uff01\u6b62\u307e\u308a\u3067\u3002<br \/>\n\u3067\u3082\u306d\u3001\u5358\u306b\u81ea\u5206\u81ea\u8eab\u304c\u6620\u753b\u3084\u30a2\u30cb\u30e1\u3088\u308a\u3082\u5c0f\u8aac\u306e\u307b\u3046\u304c\u597d\u304d\u3063\u3066\u3053\u3068\u304b\u3082\u3057\u308c\u306a\u3044\u3093\u3060\u306a\u3002<\/p>\n<p>\u81ea\u5206\u3067\u3082\u81ea\u5206\u81ea\u8eab\u306e\u3053\u3068\u3092\u305d\u3093\u306a\u306b\u77e5\u3089\u306a\u304b\u3063\u305f\u308a\u3059\u308b\u3093\u3060\u304b\u3089\u306d\u3002<\/p>\n<div class='wp_social_bookmarking_light'>        <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.vincentina.net\/?p=4957\" data-text=\"Ruby \u306e\u52c9\u5f37\u3092\u521d\u3081\u3066\u6c17\u306b\u306a\u3063\u305f\u3068\u3053\u308d\u3092\u3042\u308c\u3053\u308c 2\" data-via=\"TakekenTw\" data-lang=\"ja\">Tweet<\/a><\/div><\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Ruby\u306e\u52c9\u5f37\u3092\u521d\u3081\u3066\u304b\u3089\u3001\u305f\u3060\u3044\u307e\u30d1\u30fc\u30d5\u30a7\u30af\u30c8Ruby\u3068\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9eRuby\u3068\u3044\u3046\u66f8\u7c4d\u3092\u4e26\u884c\u3057\u3066\u9032\u3081\u308b\u30ab\u30cb\u30d0\u30b5\u30df\u52c9\u5f37\u4e2d\u3002\u3053\u306e2\u518a\u3092\u540c\u6642\u306b\u9032\u3081\u3066\u307f\u3066\u6c17\u306b\u306a\u3063\u305f\u3068\u3053\u3084\u3089\u3092\u3042\u308c\u3053\u308c\u30c4\u30e9\u30c4\u30e9\u3068\u66f8\u3044\u3066\u307f\u308b\u30d1\u30fc\u30c82 \u30fb\u30aa\u30d6\u30b8 &hellip; <a href=\"https:\/\/www.vincentina.net\/?p=4957\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Ruby \u306e\u52c9\u5f37\u3092\u521d\u3081\u3066\u6c17\u306b\u306a\u3063\u305f\u3068\u3053\u308d\u3092\u3042\u308c\u3053\u308c 2&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[106],"tags":[],"class_list":["post-4957","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts\/4957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4957"}],"version-history":[{"count":1,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts\/4957\/revisions"}],"predecessor-version":[{"id":7750,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=\/wp\/v2\/posts\/4957\/revisions\/7750"}],"wp:attachment":[{"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vincentina.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}