{"height":"190","url":"https://obelisk.hatenablog.com/entry/2016/10/06/120431","blog_url":"https://obelisk.hatenablog.com/","width":"100%","provider_name":"Hatena Blog","title":"nil \u306b\u3088\u308b NoMethodError \u3092\u56de\u907f\u3059\u308b\uff08Ruby\uff09","version":"1.0","published":"2016-10-06 12:04:31","blog_title":"Camera Obscura","author_url":"https://blog.hatena.ne.jp/obelisk2/","description":"Ruby \u306e\u30e1\u30bd\u30c3\u30c9\u3067\u4f8b\u5916\u306b nil \u3092\u8fd4\u3059\u3082\u306e\u306f\u591a\u304f\u3001NoMethodError \u304c\u51fa\u3066\u51e6\u7406\u304c\u6b62\u307e\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u9762\u5012\u306a\u306e\u3067\u56de\u907f\u3059\u308b\u30e1\u30bd\u30c3\u30c9 Object#nil_trans \u3092\u66f8\u304d\u307e\u3057\u305f\u3002self \u304c nil \u4ee5\u5916\u306e\u3068\u304d\u306f self \u3092\u305d\u306e\u307e\u307e\u8fd4\u3057\u3001nil \u306e\u3068\u304d\u306f\u5f15\u6570\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u7a7a\u6587\u5b57\u5217\uff09\u3092\u8fd4\u3057\u307e\u3059\u3002nil_trans.rb class Object def nil_trans(obj = \"\") (self == nil) ? obj : self end end \u4f8b\u3002 p nil.nil_trans #=>\"\" p nil.nil_trans(0) #=>0 p false.ni\u2026","categories":["Ruby"],"author_name":"obelisk2","provider_url":"https://hatena.blog","type":"rich","image_url":null,"html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fobelisk.hatenablog.com%2Fentry%2F2016%2F10%2F06%2F120431\" title=\"nil \u306b\u3088\u308b NoMethodError \u3092\u56de\u907f\u3059\u308b\uff08Ruby\uff09 - Camera Obscura\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>"}