{"id":8590,"date":"2019-12-17T22:59:46","date_gmt":"2019-12-17T13:59:46","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=8590"},"modified":"2023-05-27T22:33:09","modified_gmt":"2023-05-27T13:33:09","slug":"%e3%80%90ruby%e3%80%91%e5%ae%9a%e6%95%b0%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=8590","title":{"rendered":"\u3010Ruby\u3011\u5b9a\u6570\u3001\u5909\u6570\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>\u5b9a\u6570<\/h2>\n<h3>\u547d\u540d\u898f\u5247<\/h3>\n<ul>\n<li>\u5168\u3066\u5927\u6587\u5b57\u3067\u66f8\u304d\u307e\u3059\u3002\uff08\u4f8b\uff1aTAX)<\/li>\n<li>\u5358\u8a9e\u3092\u3064\u306a\u3052\u305f\u3044\u5834\u5408\u306f\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u3092\u4f7f\u3046\u3002\uff08\u4f8b\uff1aMAX_VALUE)<\/li>\n<\/ul>\n<h3>\u6ce8\u610f\u70b9<\/h3>\n<h4>\u5b9a\u6570\u3078\u306e\u4ee3\u5165\u306f\u4e00\u5ea6\u304d\u308a\u306b\u3059\u308b\u3053\u3068<\/h4>\n<p>\u518d\u4ee3\u5165\u306f\u3067\u304d\u307e\u3059\u304cWARNING\u304c\u3067\u307e\u3059\u3002\u30b3\u30fc\u30c9\u306e\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u3092\u9ad8\u3081\u308b\u305f\u3081\u306b\u306f\u5b9a\u6570\u3078\u306e\u518d\u4ee3\u5165\u306f\u907f\u3051\u307e\u3059\u3002<\/p>\n<h3>\u30af\u30e9\u30b9\u306e\u5b9a\u6570<\/h3>\n<p>\u30af\u30e9\u30b9\u306b\u5b9a\u6570\u3092\u5ba3\u8a00\u3057\u305f\u5834\u5408\u306f<span style=\"color: #ff0000;\"><strong>\u5404\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5171\u901a\u3067\u53c2\u7167\u3055\u308c\u308b<\/strong><\/span>\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u4e0b\u8a18\u306e\u65b9\u6cd5\u3067\u30af\u30e9\u30b9\u5916\u304b\u3089\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h4>\u69cb\u6587<\/h4>\n<p>\u4e0b\u8a18\u306e\u69cb\u6587\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30af\u30e9\u30b9\u5185\u90e8\u306b\u5b9a\u7fa9\u3055\u308c\u305f\u5b9a\u6570\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30af\u30e9\u30b9\u540d::\u5b9a\u6570\u540d<\/pre>\n<h4>\u4f8b<\/h4>\n<pre class=\"lang:default decode:true\">#\u52d5\u7269\u30af\u30e9\u30b9\u306e\u5b9a\u7fa9\r\nclass Animals\r\n  ANIMAL_FOOD = '\u8089'\r\nend\r\n\r\n#\u5b9a\u6570\u306e\u5024\u3092\u8868\u793a\r\nputs Animals::ANIMAL_FOOD<\/pre>\n<p>\u306a\u304a\u3001\u30af\u30e9\u30b9\u5185\u90e8\u3067\u306f\u5b9a\u6570\u306f<span style=\"color: #ff0000;\"><strong>\u5927\u6587\u5b57\u3067\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u4e00\u822c\u7684\u3067\u3001\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u3067\u5358\u8a9e\u306e\u610f\u5473\u3092\u533a\u5207\u308a\u307e\u3059\u3002<\/strong><\/span><\/p>\n<h3>\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u5b9a\u6570\u306e\u547c\u3073\u51fa\u3057<\/h3>\n<p>\u307b\u307c\u30af\u30e9\u30b9\u3068\u540c\u3058\u3088\u3046\u306b\u8a18\u8ff0\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u30e2\u30b8\u30e5\u30fc\u30eb\u540d::\u5b9a\u6570\u540d<\/pre>\n<p>\u306a\u304a\u3001\u30e2\u30b8\u30e5\u30fc\u30eb\u3092include\u3057\u305f\u5f8c\u3067\u3042\u308c\u3070<span style=\"color: #ff0000;\"><strong>\u300c\u30e2\u30b8\u30e5\u30fc\u30eb\u540d::\u300d<\/strong><strong>\u306e\u8a18\u8ff0\u306f\u7701\u7565\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<h2>\u5909\u6570<\/h2>\n<p>\u300c\u5909\u6570\u540d=\u5024\u300d\u3068\u3044\u3046\u5f62\u3067\u5909\u6570\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">str = 'Hello World'<\/pre>\n<p>\u307e\u305f\u3001\u5ba3\u8a00\u3059\u308b\u969b\u306f\u5fc5\u305a\u4f55\u304b\u3057\u3089\u306e\u5024\u3092\u5165\u529b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u4ed5\u7d44\u307f<\/h3>\n<p>\u306a\u304a\u3001Ruby\u306e\u5909\u6570\u306f<span style=\"color: #ff0000;\"><strong>\u5168\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong><\/span>\u306b\u306a\u308a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u306e\u53c2\u7167\u304c\u683c\u7d0d\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5225\u306e\u5909\u6570\u306b\u5909\u6570\u3092\u683c\u7d0d\u3059\u308b\u3068<span style=\"color: #ff0000;\"><strong>\u540c\u3058\u53c2\u7167\u5148\u3092\u898b\u308b\u5909\u6570<\/strong><\/span>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">a = 'Hello, world!'\r\nputs a.object_id<\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b<span style=\"color: #ff0000;\"><strong>\u300cobject_id\u300d<\/strong><\/span>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3053\u3068\u3067\u305d\u306e<span style=\"color: #ff0000;\"><strong>\u5909\u6570\u306e\u53c2\u7167\u5148ID\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u3053\u306eID\u304c\u540c\u3058\u3067\u3042\u308c\u3070\u540c\u3058\u53c2\u7167\u5148\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>\u5909\u6570\u306e\u547d\u540d\u898f\u5247<\/h3>\n<ul>\n<li>\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u306e\u5c0f\u6587\u5b57\u304b\u3001\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u3067\u59cb\u3081\u308b\u3002(\u4f8b\uff1aprice\u3001_price)<\/li>\n<li>\u8907\u6570\u306e\u5358\u8a9e\u3092\u3064\u306a\u3052\u308b\u5834\u5408\u306f\u30b9\u30cd\u30fc\u30af\u30b1\u30fc\u30b9\u3067\u66f8\u304f\uff08\u4f8b\uff1arow_price)<\/li>\n<\/ul>\n<h3>\u9ad8\u5ea6\u306a\u5909\u6570\u3078\u306e\u4ee3\u5165<\/h3>\n<p>\u5de6\u304b\u3089\u8a55\u4fa1\u3057\u3066\u884c\u3063\u3066nil\u3067\u3082false\u3067\u3082\u306a\u3044\u5909\u6570\u3092\u898b\u3064\u3051\u305f\u3089\u4ee3\u5165\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u5909\u6570A = \u5909\u6570B || \u5909\u6570C<\/pre>\n<h4>\u7279\u6b8a\u306a\u4ee3\u5165<\/h4>\n<p>\u4ee3\u5165\u5148\u306e\u5909\u6570\u304c<span style=\"color: #ff0000;\"><strong>nil\u307e\u305f\u306ffalse\u3067\u3042\u308b\u5834\u5408\u306b\u53f3\u8fba\u306b\u3042\u308b\u5024\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002<\/strong><\/span><\/p>\n<pre class=\"lang:default decode:true \">\u5909\u6570 ||= \u5024<\/pre>\n<h3>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570<\/h3>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u3069\u3053\u304b\u3089\u3067\u3082\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">$\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u540d<\/pre>\n<h3>\u7591\u4f3c\u5909\u6570<\/h3>\n<p>Ruby\u30d7\u30ed\u30b0\u30e9\u30e0\u5185\u3067\u5e38\u306b\u5024\u304c\u5165\u3063\u3066\u3044\u308b<span style=\"color: #ff0000;\"><strong>\u7279\u6b8a\u306a\u5909\u6570<\/strong><\/span>\u3067\u3059\u3002\u4e0b\u8a18\u5909\u6570\u306b\u5024\u3092\u4ee3\u5165\u3057\u3088\u3046\u3068\u3057\u3066\u3082\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<th>\u7591\u4f3c\u5909\u6570\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>nil<\/td>\n<td>NULL<\/td>\n<\/tr>\n<tr>\n<td>true<\/td>\n<td>\u771f\u507d\u5024\u306e\u771f<\/td>\n<\/tr>\n<tr>\n<td>false<\/td>\n<td>\u771f\u507d\u5024\u306e\u507d<\/td>\n<\/tr>\n<tr>\n<td>self<\/td>\n<td>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u81ea\u8eab<\/td>\n<\/tr>\n<tr>\n<td>__FILE_<\/td>\n<td>\u73fe\u5728\u306e\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u540d<\/td>\n<\/tr>\n<tr>\n<td>__LINE_<\/td>\n<td>\u73fe\u5728\u306e\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u306e\u884c\u756a\u53f7<\/td>\n<\/tr>\n<tr>\n<td>__ENCODING__<\/td>\n<td>\u73fe\u5728\u306e\u30bd\u30fc\u30b9\u30d5\u30a1\u30a4\u30eb\u306e\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b9a\u6570 \u547d\u540d\u898f\u5247 \u5168\u3066\u5927\u6587\u5b57\u3067\u66f8\u304d\u307e\u3059\u3002\uff08\u4f8b\uff1aTAX) \u5358\u8a9e\u3092\u3064\u306a\u3052\u305f\u3044\u5834\u5408\u306f\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u3092\u4f7f\u3046\u3002\uff08\u4f8b\uff1aMAX_VALUE) \u6ce8\u610f\u70b9 \u5b9a\u6570\u3078\u306e\u4ee3\u5165\u306f\u4e00\u5ea6\u304d\u308a\u306b\u3059\u308b\u3053\u3068 \u518d\u4ee3\u5165\u306f\u3067\u304d\u307e\u3059\u304cWARNING\u304c\u3067\u307e\u3059\u3002\u30b3\u30fc\u30c9\u306e\u30e1 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[48],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8590"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8590"}],"version-history":[{"count":9,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8590\/revisions"}],"predecessor-version":[{"id":20474,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/8590\/revisions\/20474"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8590"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}