<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>sunjohn (宋均)</title>
    <link>https://ruby-china.org/sunjohn</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>实验数据处理问题</title>
      <description>&lt;p&gt;实验数据 40000 个左右，存为一个 txt 文件中，每行一个数据：
想要每隔 100 行取一个数据，结果输出为 txt 文档
请问用 ruby 如何实现？&lt;/p&gt;</description>
      <author>sunjohn</author>
      <pubDate>Tue, 08 Jan 2013 17:14:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/7882</link>
      <guid>https://ruby-china.org/topics/7882</guid>
    </item>
    <item>
      <title>instance_eval 冲破封装问题</title>
      <description>&lt;p&gt;看 ruby 元编程，读到 instance_eval() 方法时，作者说他会打破封装，没有什么数据时私有的了。
那么有没有啥办法避免这种状况？&lt;/p&gt;</description>
      <author>sunjohn</author>
      <pubDate>Thu, 18 Oct 2012 09:39:21 +0800</pubDate>
      <link>https://ruby-china.org/topics/6137</link>
      <guid>https://ruby-china.org/topics/6137</guid>
    </item>
    <item>
      <title>从数组中随机选择若干元素</title>
      <description>&lt;p&gt;从 &lt;code&gt;array = [1, 2, 3, 4, 5]&lt;/code&gt; 中随机选择 n 个数，这 n 个数的结果要以数组给出。&lt;/p&gt;

&lt;p&gt;写了个 method
&lt;code&gt;def select_random(array, n)&lt;/code&gt;
   &lt;code&gt;array.shuffle.drop(array.size - n)&lt;/code&gt;
&lt;code&gt;end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;觉得有点怪，麻烦各位给看下，有没有好的方法，谢谢啊！&lt;/p&gt;</description>
      <author>sunjohn</author>
      <pubDate>Sun, 14 Oct 2012 10:28:34 +0800</pubDate>
      <link>https://ruby-china.org/topics/6045</link>
      <guid>https://ruby-china.org/topics/6045</guid>
    </item>
    <item>
      <title>ruby 如何实现连减</title>
      <description>&lt;p&gt;任意长度的数组，如何实现累减？
如：
&lt;code&gt;[1, 2, 3, 4, 5]&lt;/code&gt;
计算结果为： -13
我用的是这个：&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;subtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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="n"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;n&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;但是感觉很别扭，有没有更简单的？&lt;/p&gt;</description>
      <author>sunjohn</author>
      <pubDate>Fri, 12 Oct 2012 11:17:20 +0800</pubDate>
      <link>https://ruby-china.org/topics/6018</link>
      <guid>https://ruby-china.org/topics/6018</guid>
    </item>
  </channel>
</rss>
