<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>rockliu (Rocco Liu)</title>
    <link>https://ruby-china.org/rockliu</link>
    <description>哥们儿，别认真，认真就输了</description>
    <language>en-us</language>
    <item>
      <title>用 * 号在数组内展开 Range 对象</title>
      <description>&lt;p&gt;今天在 Qiita 上面看到一段模仿黑客帝国刷屏的小程序
代码如下&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;gori_yes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&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="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="s1"&gt;'z'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="s1"&gt;'A'&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="s1"&gt;'Z'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="kp"&gt;loop&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
 &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="n"&gt;gori_yes&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;gori_yes&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;
 &lt;span class="nb"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;发现这种写法挺好的，在数组中 Range 对象前面加个*号展开这个对象&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;  &lt;span class="c1"&gt;# =&amp;gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>rockliu</author>
      <pubDate>Wed, 08 May 2013 15:09:43 +0800</pubDate>
      <link>https://ruby-china.org/topics/10820</link>
      <guid>https://ruby-china.org/topics/10820</guid>
    </item>
    <item>
      <title>分享一个网站，可以很方便得到 Mac 键盘上的键对应的符号</title>
      <description>&lt;p&gt;今天写东西要输入 mac 上键对应的这种⌘，⇧符号，觉得这个网站蛮方便的
&lt;a href="http://mackeys.info/" rel="nofollow" target="_blank"&gt;http://mackeys.info/&lt;/a&gt;&lt;/p&gt;</description>
      <author>rockliu</author>
      <pubDate>Sun, 05 May 2013 20:04:26 +0800</pubDate>
      <link>https://ruby-china.org/topics/10728</link>
      <guid>https://ruby-china.org/topics/10728</guid>
    </item>
    <item>
      <title>Ruby 2.0 中增加了将 nil 转成哈希对象的方法 nil.to_h</title>
      <description>&lt;p&gt;ruby2.0 以前，像下面的方法 如果 hash 为 nil 直接爆掉！&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_nil_to_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"follow"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;test_nil_to_hash&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s2"&gt;"follow"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"me"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; "me"&lt;/span&gt;
&lt;span class="n"&gt;test_nil_to_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;#=&amp;gt; undefined method `[]' for nil:NilClass (NoMethodError)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;我们要避免抛出 NoMethodError 一般会这么写：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_nil_to_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;{})[&lt;/span&gt;&lt;span class="s2"&gt;"follow"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;test_nil_to_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt;  nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;从 ruby2.0 开始增加了Nil#to_h方法, (hash || {}) 这种写法成为历史啦！ &lt;img title=":scream:" alt="😱" src="https://twemoji.ruby-china.com/2/svg/1f631.svg" class="twemoji"&gt;&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_nil_to_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_h&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"follow"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>rockliu</author>
      <pubDate>Fri, 03 May 2013 12:06:05 +0800</pubDate>
      <link>https://ruby-china.org/topics/10680</link>
      <guid>https://ruby-china.org/topics/10680</guid>
    </item>
    <item>
      <title> Linux Deepin  深度 linux 让人眼前一亮啊</title>
      <description>&lt;p&gt;刚刚发现深度 linux 界面很漂亮，基于 ubuntu 的。
&lt;a href="http://www.linuxdeepin.com/" rel="nofollow" target="_blank"&gt;http://www.linuxdeepin.com/&lt;/a&gt;  &lt;/p&gt;</description>
      <author>rockliu</author>
      <pubDate>Thu, 16 Feb 2012 18:03:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/1240</link>
      <guid>https://ruby-china.org/topics/1240</guid>
    </item>
    <item>
      <title>godaddy 的 dns 用不了了。。。连 mongoid.org 都要 FQ 了。</title>
      <description>&lt;p&gt;今天一访问自己的博客，显示找不到 dns 就感觉不妙了。
测试了几下其他的 godadday 域名，全部悲剧了。
godaddy 的主页打不开了（FQ 后可以打开）。。。
mongoid.org 也打不开了（FQ 后可以打开，估计也是 godadday 的 dns）&lt;/p&gt;

&lt;p&gt;不知道其他人的 godadday 域名，还正常吗？怀疑是大规模封杀。&lt;/p&gt;</description>
      <author>rockliu</author>
      <pubDate>Sun, 18 Dec 2011 19:31:31 +0800</pubDate>
      <link>https://ruby-china.org/topics/520</link>
      <guid>https://ruby-china.org/topics/520</guid>
    </item>
    <item>
      <title>使用 mongoid_auto_inc 来为你的 mongoid 添加自增字段</title>
      <description>&lt;p&gt;大部分的人都不太喜欢 mongodb 那一长串 id，都会选择自己去重写 id 为更具亲和力的自增数字。
发现了一个比较好用的 gem，可以帮我们完成这项工作。
使用 auto_increment 来指定自增字段。
详细的用法 github 上有说明:
地址 &lt;a href="https://github.com/jffjs/mongoid_auto_inc" rel="nofollow" target="_blank"&gt;https://github.com/jffjs/mongoid_auto_inc&lt;/a&gt;  &lt;/p&gt;</description>
      <author>rockliu</author>
      <pubDate>Sun, 04 Dec 2011 15:25:09 +0800</pubDate>
      <link>https://ruby-china.org/topics/346</link>
      <guid>https://ruby-china.org/topics/346</guid>
    </item>
    <item>
      <title>点击帖子之后会跳到评论部分而不是正文部分</title>
      <description>&lt;p&gt;如果一篇帖子比较长，点击进去查看会跳到页面下方的评论部分，我觉得这个应该改进一下。浏览起来不是很方便，需要向上滚动。  &lt;/p&gt;</description>
      <author>rockliu</author>
      <pubDate>Tue, 22 Nov 2011 14:28:27 +0800</pubDate>
      <link>https://ruby-china.org/topics/109</link>
      <guid>https://ruby-china.org/topics/109</guid>
    </item>
  </channel>
</rss>
