{"id":11393,"date":"2020-07-26T10:10:34","date_gmt":"2020-07-26T01:10:34","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=11393"},"modified":"2023-05-27T22:47:00","modified_gmt":"2023-05-27T13:47:00","slug":"%e3%80%90ruby-on-rails%e3%80%91%e7%a9%ba%e6%96%87%e5%ad%97%e3%80%81nil%e3%83%81%e3%82%a7%e3%83%83%e3%82%af%e3%81%ae%e7%a8%ae%e9%a1%9e","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=11393","title":{"rendered":"\u3010Ruby on Rails\u3011\u7a7a\u6587\u5b57\u3001nil\u30c1\u30a7\u30c3\u30af\u306e\u7a2e\u985e(present?\u3001empty?\u3001blank?\u3001nil?)\u3001ActiveSupport"},"content":{"rendered":"<p>Rails\u3067\u306e\u7a7a\u6587\u5b57\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3053\u3068\u304c\u666e\u901a\u3067\u3059\u304c\u8272\u3005\u7a2e\u985e\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>empty?<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>Ruby\u6a19\u6e96\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3067\u3059\u3002\u6587\u5b57\u5217\u304b\u914d\u5217\u306e\u4e2d\u8eab\u304c\u7a7a\u306e\u5834\u5408\u306btrue\u3092\u8fd4\u3057\u307e\u3059\u3002\u7a7a\u767d\u306e\u307f\u306e\u6587\u5b57\u5217(\"\u00a0 \")\u306ffalse\u3092\u8fd4\u3057\u307e\u3059\u3057\u3001nil\u3084true\u3084false\u3001Integer(\u6570\u5024)\u306b\u306f\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u305b\u3093\u3002(NoMethodError\u306b\u306a\u308a\u307e\u3059\u3002)<\/p>\n<h2>nil?<\/h2>\n<p><strong><span style=\"color: #ff0000;\">Ruby\u6a19\u6e96\u30e1\u30bd\u30c3\u30c9<\/span><\/strong>\u3067\u3059\u3002\u6587\u5b57\u5217\u3084\u914d\u5217\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u306e\u307f(nil\u306e\u5834\u5408\u306e\u307f)\u306btrue\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<h2>blank?<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>ActiveSupport(Rails)\u3067\u62e1\u5f35\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3067\u3059\u3002nil\u3001\u7a7a\u6587\u5b57(\"\")\u3001\u7a7a\u767d\u306e\u307f\u306e\u6587\u5b57\u5217(\"\u00a0 \u00a0\")\u3001\u7a7a\u914d\u5217\u3001\u7a7a\u30cf\u30c3\u30b7\u30e5\u3001false\u7b49\u3067\u3082true\u3092\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002\u5bfe\u5fdc\u3067\u304d\u308b\u7bc4\u56f2\u304c\u5e83\u3044\u306e\u3067\u6240\u69cb\u308f\u305a\u4f7f\u3046\u3068\u610f\u56f3\u304c\u8aad\u307f\u3065\u3089\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u7279\u306b\u7a7a\u767d\u306e\u30b9\u30da\u30fc\u30b9\u306a\u3069\u304ctrue\u304c\u5e30\u3063\u3066\u304f\u308b\u306e\u306f\u6ce8\u610f\u3068\u8a00\u3048\u308b\u3067\u3057\u3087\u3046\u3002\uff08empty?\u3067\u306ffalse\u304c\u5e30\u308b\u306e\u3067\u3002\uff09<\/p>\n<p>present?\u30e1\u30bd\u30c3\u30c9\u306e\u9006\u3067\u3059\u3002\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5b58\u5728\u3057\u306a\u3051\u308c\u3070true\u3001\u5b58\u5728\u3059\u308c\u3070false\u3092\u8fd4\u3059\u3002<\/p>\n<h3>\u7528\u9014<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>nil\u3068\u7a7a\u6587\u5b57\u3068\u7a7a\u767d\u306e\u307f\u306e\u6587\u5b57\u5217\u3092\u540c\u69d8\u306e\u8a55\u4fa1\u3068\u3057\u305f\u3044\u5834\u5408<\/strong><\/span>\u306b\u4f7f\u3044\u307e\u3059\u3002nil\u3068\u7a7a\u6587\u5b57\u3084\u7a7a\u767d\u306e\u307f\u306e\u6587\u5b57\u5217\u3067\u8a55\u4fa1\u3092\u5206\u3051\u305f\u3044\u5834\u5408\u306fnil?\u3084empty?\u3092\u4f7f\u3046\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u8aad\u307f\u624b\u306b\u610f\u56f3\u304c\u660e\u78ba\u306b\u4f1d\u308f\u308a\u307e\u3059\u3002<\/p>\n<h2>present?<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>ActiveSupport(Rails)\u3067\u62e1\u5f35\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3067\u3059\u3002blank?\u306e\u9006\u3067\u3001!blank?\u3068\u306f\u540c\u3058\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5024\u304c\u5b58\u5728\u3059\u308b\u304b\u3069\u3046\u304b\u771f\u507d\u3092\u8fd4\u3057\u307e\u3059\u3002\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5b58\u5728\u3059\u308c\u3070true\u3001\u5b58\u5728\u3057\u306a\u3051\u308c\u3070false\u3092\u8fd4\u3059\u3002(\u5177\u4f53\u7684\u306b\u306fnil\u3001false\u3001\"\"\u3001\" \"\u3001[]\u3001{}\u306e\u5834\u5408\u306ffalse\u306b\u306a\u308b\u3002)<\/p>\n<p>\u306a\u304a\u3001<span style=\"color: #ff0000;\"><strong>\u6570\u5024\u306e0(\u30bc\u30ed\uff09\u306f\u5024\u304c\u5b58\u5728\u3059\u308b\u3068\u307f\u306a\u3055\u308c\u308b\u306e\u3067\u6ce8\u610f<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<h2>ActiveSupport\u3068\u306f\uff1f<\/h2>\n<p><span style=\"color: #ff0000;\"><strong>Rails\u3092\u4f7f\u3063\u3066\u958b\u767a\u3092\u3059\u308b\u4e0a\u3067\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u7b49\u3092\u307e\u3068\u3081\u305f\u30e9\u30a4\u30d6\u30e9\u30ea<\/strong><\/span>\u3067\u3059\u3002\u7d14\u7c8b\u306aRuby\u306b\u306f\u5b58\u5728\u3057\u307e\u305b\u3093\u3002<\/p>\n<h3>ActiveSupport\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308b\u6a5f\u80fd<\/h3>\n<p>present?\u30e1\u30bd\u30c3\u30c9\u3001blank?\u30e1\u30bd\u30c3\u30c9\u306e\u4ed6\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>starts_with?\u30e1\u30bd\u30c3\u30c9<\/h4>\n<p>\u5b9f\u969b\u306eRuby\u306estart_with\u30e1\u30bd\u30c3\u30c9\u3068\u540c\u3058\u3067\u3059\u304c\u300cs\u300d\u304c\u3064\u304f\u306e\u3067\u6ce8\u610f\u3067\u3059\u3002<\/p>\n<h4>ends_with?\u30e1\u30bd\u30c3\u30c9<\/h4>\n<p>\u5b9f\u969b\u306eRuby\u306eend_with\u30e1\u30bd\u30c3\u30c9\u3068\u540c\u3058\u3067\u3059\u304c\u300cs\u300d\u304c\u3064\u304f\u306e\u3067\u6ce8\u610f\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Rails\u3067\u306e\u7a7a\u6587\u5b57\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3053\u3068\u304c\u666e\u901a\u3067\u3059\u304c\u8272\u3005\u7a2e\u985e\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002 empty? Ruby\u6a19\u6e96\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u6587\u5b57\u5217\u304b\u914d\u5217\u306e\u4e2d\u8eab\u304c\u7a7a\u306e\u5834\u5408\u306btrue\u3092\u8fd4\u3057\u307e\u3059\u3002\u7a7a\u767d\u306e\u307f\u306e\u6587\u5b57\u5217(\"\u00a0 \")\u306ffalse\u3092\u8fd4 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[36],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/11393"}],"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=11393"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/11393\/revisions"}],"predecessor-version":[{"id":20509,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/11393\/revisions\/20509"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}