<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>obelisk2</author_name>
  <author_url>https://blog.hatena.ne.jp/obelisk2/</author_url>
  <blog_title>Camera Obscura</blog_title>
  <blog_url>https://obelisk.hatenablog.com/</blog_url>
  <categories>
    <anon>Ruby</anon>
  </categories>
  <description>Ruby のメソッドで例外に nil を返すものは多く、NoMethodError が出て処理が止まることがあります。面倒なので回避するメソッド Object#nil_trans を書きました。self が nil 以外のときは self をそのまま返し、nil のときは引数（デフォルトは空文字列）を返します。nil_trans.rb class Object def nil_trans(obj = &quot;&quot;) (self == nil) ? obj : self end end 例。 p nil.nil_trans #=&gt;&quot;&quot; p nil.nil_trans(0) #=&gt;0 p false.ni…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fobelisk.hatenablog.com%2Fentry%2F2016%2F10%2F06%2F120431&quot; title=&quot;nil による NoMethodError を回避する（Ruby） - Camera Obscura&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2016-10-06 12:04:31</published>
  <title>nil による NoMethodError を回避する（Ruby）</title>
  <type>rich</type>
  <url>https://obelisk.hatenablog.com/entry/2016/10/06/120431</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
