<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>thisiskun</title>
    <link>https://ruby-china.org/thisiskun</link>
    <description>怒攒人品</description>
    <language>en-us</language>
    <item>
      <title>Ruby 如何实现与 nil 的比较都返回 true (已解决)</title>
      <description>&lt;p&gt;想自己实现一个小型的 DSL，绑定变量后，让表达式返回布尔值，比如：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;如何让如上表达式在&lt;code&gt;a.foo&lt;/code&gt;与&lt;code&gt;a.bar&lt;/code&gt;只要一个为 nil，就返回 true？&lt;/p&gt;

&lt;p&gt;对于&lt;code&gt;a.foo&lt;/code&gt;为 nil 的情况，我是这样实现的：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NilClass&lt;/span&gt;
  &lt;span class="nb"&gt;methods&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:&amp;lt;=&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:==&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nb"&gt;methods&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;method&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;define_method&lt;/span&gt; &lt;span class="nb"&gt;method&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;arg&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;对于&lt;code&gt;a.foo&lt;/code&gt;不为 nil（&lt;code&gt;a.foo&lt;/code&gt;可以是任何数据类型），但是&lt;code&gt;a.bar&lt;/code&gt;为 nil 的情况，如何实现呢？&lt;/p&gt;</description>
      <author>thisiskun</author>
      <pubDate>Wed, 16 Sep 2015 16:38:57 +0800</pubDate>
      <link>https://ruby-china.org/topics/27365</link>
      <guid>https://ruby-china.org/topics/27365</guid>
    </item>
    <item>
      <title>你心中的高帅富程序员是如何的？</title>
      <description>&lt;p&gt;各位可以各抒己见哈~~  &lt;/p&gt;</description>
      <author>thisiskun</author>
      <pubDate>Mon, 09 Apr 2012 15:00:58 +0800</pubDate>
      <link>https://ruby-china.org/topics/2482</link>
      <guid>https://ruby-china.org/topics/2482</guid>
    </item>
  </channel>
</rss>
