<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>linusliu (liuyang)</title>
    <link>https://ruby-china.org/linusliu</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>Class variable, instance variable 和 class instance variable 辨析（2）</title>
      <description>&lt;p&gt;instance variable 没什么太多可说的，就是实例属性，每个实例都可以保存不同的值，互不干扰。实例属性是@加属性名。看下例：&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;Square&lt;/span&gt;
   &lt;span class="nb"&gt;attr_accessor&lt;/span&gt; &lt;span class="ss"&gt;:side&lt;/span&gt;
   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@side&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;len&lt;/span&gt;
   &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;p&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;side&lt;/span&gt;
&lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;side&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;side&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;side&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;
&lt;span class="nb"&gt;p&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;side&lt;/span&gt;
&lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;side&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;在 initialize 方法中，我们初始化了&lt;a href="/side" class="user-mention" title="@side"&gt;&lt;i&gt;@&lt;/i&gt;side&lt;/a&gt;这个实例属性。但我挺不习惯的是，在定义实例属性时是&lt;a href="/side" class="user-mention" title="@side"&gt;&lt;i&gt;@&lt;/i&gt;side&lt;/a&gt;,但引用时却是 side.&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Sun, 10 Aug 2014 15:37:19 +0800</pubDate>
      <link>https://ruby-china.org/topics/20940</link>
      <guid>https://ruby-china.org/topics/20940</guid>
    </item>
    <item>
      <title>请问有谁用过 cramp 吗？想请教一个问题</title>
      <description>&lt;p&gt;按照 cramp 的官方文档，下载安装 cramp 后，自动生成了一个文件夹 chat。里面有 chat\app\actions\home_action.rb.
在启动 cramp 后，打开浏览器会看到欢迎文件，这个欢迎文件是在 home_action.rb 中写的
class HomeAction &amp;lt; Cramp::Action
  def start
    render "Hello World!"&lt;/p&gt;

&lt;p&gt;# Do more stuff&lt;/p&gt;

&lt;p&gt;render "Hello World Again!"
    finish
  end
end&lt;/p&gt;

&lt;p&gt;我想请问的是，为什么打开 localhost:3000，就会自动调用 home_action.rb 的内容？这是在哪设置的？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Wed, 06 Aug 2014 08:22:21 +0800</pubDate>
      <link>https://ruby-china.org/topics/20862</link>
      <guid>https://ruby-china.org/topics/20862</guid>
    </item>
    <item>
      <title>关于 git 分支的一个问题，请教各位</title>
      <description>&lt;p&gt;有这样一段话，我不是很理解，请大家帮我分析一下&lt;/p&gt;

&lt;p&gt;“分支在实际中有什么用呢？假设你准备开发一个新功能，但是需要两周才能完成，第一周你写了 50% 的代码，如果立刻提交，由于代码还没写完，不完整的代码库会导致别人不能干活了。如果等代码全部写完再一次提交，又存在丢失每天进度的巨大风险。”&lt;/p&gt;

&lt;p&gt;我的理解是每个人都从 github clone 一套版本，各干各的。然后提交，推送到 github。所以上面说的这种情况，我觉得只要在本地 commit，而不推送到 github，就不会影响其他人的工作。是不是这样？&lt;/p&gt;

&lt;p&gt;我觉得一种情况需要分支的是自己同时要开发几个新功能，那么每个功能建立一个分支。不知这么理解对不对。&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Mon, 04 Aug 2014 16:25:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/20833</link>
      <guid>https://ruby-china.org/topics/20833</guid>
    </item>
    <item>
      <title>请教一个 git stash 的问题</title>
      <description>&lt;p&gt;本人完全是 Git 新手，在看一个人的帖子，其中有一段关于 stah 的介绍，有点不好理解，所以拿到这里来，请教大家一下：&lt;/p&gt;
&lt;h2 id="原文是这么说的："&gt;原文是这么说的：&lt;/h2&gt;
&lt;p&gt;软件开发中，bug 就像家常便饭一样。有了 bug 就需要修复，在 Git 中，由于分支是如此的强大，所以，每个 bug 都可以通过一个新的临时分支来修复，修复后，合并分支，然后将临时分支删除。&lt;/p&gt;

&lt;p&gt;当你接到一个修复一个代号 101 的 bug 的任务时，很自然地，你想创建一个分支 issue -101 来修复它，但是，等等，当前正在 dev 上进行的工作还没有提交：
$ git status&lt;/p&gt;
&lt;h2 id="On branch dev"&gt;On branch dev&lt;/h2&gt;&lt;h2 id="Changes to be committed:"&gt;Changes to be committed:&lt;/h2&gt;&lt;h2 id="(use "&gt;(use "git reset HEAD ..." to unstage)
&lt;/h2&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;h2 id="new file:   hello.py"&gt;new file:   hello.py&lt;/h2&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;h2 id="Changes not staged for commit:"&gt;Changes not staged for commit:&lt;/h2&gt;&lt;h2 id="(use "&gt;(use "git add ..." to update what will be committed)
&lt;/h2&gt;&lt;h2 id="(use "&gt;(use "git checkout -- ..." to discard changes in working directory)
&lt;/h2&gt;
&lt;p&gt;#&lt;/p&gt;
&lt;h2 id="modified:   readme.txt"&gt;modified:   readme.txt&lt;/h2&gt;
&lt;p&gt;#&lt;/p&gt;

&lt;p&gt;并不是你不想提交，而是工作只进行到一半，还没法提交，预计完成还需 1 天时间。但是，必须在两个小时内修复该 bug，怎么办？&lt;/p&gt;

&lt;p&gt;幸好，Git 还提供了一个 stash 功能，可以把当前工作现场“储藏”起来，等以后恢复现场后继续工作：
$ git stash
Saved working directory and index state WIP on dev: 6224937 add merge
HEAD is now at 6224937 add merge&lt;/p&gt;
&lt;h2 id="现在，用git status查看工作区，就是干净的（除非有没有被Git管理的文件），因此可以放心地创建分支来修复bug。"&gt;现在，用 git status 查看工作区，就是干净的（除非有没有被 Git 管理的文件），因此可以放心地创建分支来修复 bug。&lt;/h2&gt;
&lt;p&gt;我不理解的是，为什么要先 stash 一个分支（在此例中是 dev 分支），然后才能回到 master 再新开一个分支。我不 stash dev 分支，直接回到 master，好像也可以，请问其中有什么原因吗？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Wed, 30 Jul 2014 12:51:20 +0800</pubDate>
      <link>https://ruby-china.org/topics/20748</link>
      <guid>https://ruby-china.org/topics/20748</guid>
    </item>
    <item>
      <title>关于 EventMachine 的概念，请教！</title>
      <description>&lt;p&gt;以前从没有考虑过多线程或并发什么的，但下一个工作需要 EM 的知识，现在刚开始学，比较吃力。有一个概念想请教大家一下：
&lt;img src="https://l.ruby-china.com/photo/2014/adcee14e5c6cae2bc6456203890daf67.png" title="" alt=""&gt;&lt;/p&gt;

&lt;p&gt;肯定好多地方说的都不准确，大家包涵。
在介绍 EM 时，一个常见的例子就是
require 'rubygems'&lt;br&gt;
02.require 'eventmachine'  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; 
04.class Echo &amp;lt; EM::Connection&lt;br&gt;
&lt;/li&gt;
&lt;li&gt; def receive_data(data)&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;   send_data(data)&lt;br&gt;
&lt;/li&gt;
&lt;li&gt; end&lt;br&gt;
08.end&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;br&gt;
10.EM.run do&lt;br&gt;
&lt;/li&gt;
&lt;li&gt; EM.start_server("0.0.0.0", 10000, Echo)&lt;br&gt;
12.end 
那么 EM.run 实际上是启动了一个 reactor.根据上图，我是否可以理解那个 class Echo 就是注册的一个 Event handler？当这个 reactor 在
("0.0.0.0", 10000）监听到一个事件，那么就调用 Echo 来处理，请问这样理解对吗？&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;关于 EM 的介绍文章，一般都会谈及 EM 自己的几个函数，比如 add_timer 或 add_periodic_timer.我是否可以这么理解，时间到了，就会触发一个事件，然后就会调用相应的回调函数，这里回调函数就是 event handler, 和 class Echo 起相同的作用？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Wed, 23 Jul 2014 11:59:56 +0800</pubDate>
      <link>https://ruby-china.org/topics/20635</link>
      <guid>https://ruby-china.org/topics/20635</guid>
    </item>
    <item>
      <title>EventMachine 和 cramp 有人用吗？</title>
      <description>&lt;p&gt;新的公司要使用 EventMachine 和 cramp，我在网上查了一下，几乎找不到有什么中文资料。请问谁能推荐点教材吗？还有，这俩是干什么的啊？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Tue, 22 Jul 2014 08:16:55 +0800</pubDate>
      <link>https://ruby-china.org/topics/20617</link>
      <guid>https://ruby-china.org/topics/20617</guid>
    </item>
    <item>
      <title>app/views/layouts/application.html.erb 报错</title>
      <description>&lt;p&gt;自动生成的 application.html.erb 不停的报错，错误显示为：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Sprockets::Rails::Helper::AssetFilteredError in StaticPages#home
Showing C:/RailProject/sample_app/app/views/layouts/application.html.erb where line #7 raised:

Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( glyphicons-halflings-white.png )` to `config/initializers/assets.rb` and restart your server
  (in C:/RailProject/sample_app/app/assets/stylesheets/static_pages.css.scss)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这是第 7 行的内容：
&amp;lt;%= stylesheet_link_tag "application", media: "all" %&amp;gt;&lt;/p&gt;

&lt;p&gt;请教一下，这是怎么回事？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Wed, 09 Jul 2014 18:21:20 +0800</pubDate>
      <link>https://ruby-china.org/topics/20400</link>
      <guid>https://ruby-china.org/topics/20400</guid>
    </item>
    <item>
      <title>请教 HTML 中的 GET,POST,PUT,DELETE 的一个问题</title>
      <description>&lt;p&gt;我问个基础问题，我刚刚知道 HTML 中有 GET,POST,PUT,DELETE 四种请求。那么我知道在表单上传中有 GET 和 POST 两种方式来上传表单。我想问的是 HTML 中的 GET，POST 请求和表单的 GET,POST 是一会事吗？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Sat, 05 Jul 2014 12:55:15 +0800</pubDate>
      <link>https://ruby-china.org/topics/20326</link>
      <guid>https://ruby-china.org/topics/20326</guid>
    </item>
    <item>
      <title>public 文件夹中的 index 在哪？</title>
      <description>&lt;p&gt;最近在学习 rails，书上说每个项目的 public 文件夹都会有 Index.html 文件以对应首页。挺奇怪的，我的 public 文件夹里面没有 index.html，这是怎么回事？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Sat, 05 Jul 2014 11:59:41 +0800</pubDate>
      <link>https://ruby-china.org/topics/20325</link>
      <guid>https://ruby-china.org/topics/20325</guid>
    </item>
    <item>
      <title>头次使用 RubyMine 的问题，求教</title>
      <description>&lt;p&gt;我是用 railsinstaller 安装的环境。所用的东西都安装在 c:\RailsInstaller 下。
我想使用 IDE rubymine 来写 code. 当我用命令行创建一个 rails 的项目，想把它导入 rubymine 时，会出现如下的错误提示：
“Following gems were not installed:
bundler:Home path (C:/Ruby193/bin/ruby.exe) for ruby SDK 'ruby-1.9.3-p545' doesn't exist"
可是我的 ruby 是安装在 C:\RailsInstaller\Ruby1.9.3 下。
请问有什么办法吗？&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Thu, 03 Jul 2014 16:10:01 +0800</pubDate>
      <link>https://ruby-china.org/topics/20299</link>
      <guid>https://ruby-china.org/topics/20299</guid>
    </item>
    <item>
      <title>既然 Mongrel 已经是 web server 了，为何还要 apache?</title>
      <description>&lt;p&gt;我以前学过 PHP，我的理解是 apache 作为 http server，负责调用 php.
那么在 ruby 中，Mongrel 的作用应该和 apache 类似。所以我不明白，既然有个 Mongrel，为何还要安装 apache?&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Sat, 21 Jun 2014 17:02:44 +0800</pubDate>
      <link>https://ruby-china.org/topics/20098</link>
      <guid>https://ruby-china.org/topics/20098</guid>
    </item>
    <item>
      <title>在 ruby debug 中出现的问题，求教</title>
      <description>&lt;p&gt;按照书上的介绍，今天试了 ruby debug 的功能，但是不成功：
我是这么写的 ruby -r debug debugtest.rb, 目的是要测试 debugtest.rb 这个文件。
但不知为何，测试的却是 kernel_require.rb&lt;/p&gt;

&lt;p&gt;谁能给我解释一下该怎么办吗？&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2014/ac3fa8bd7b2b20e094feab2b8f6cbfbc.gif" title="" alt=""&gt;&lt;/p&gt;</description>
      <author>linusliu</author>
      <pubDate>Thu, 19 Jun 2014 07:26:18 +0800</pubDate>
      <link>https://ruby-china.org/topics/20036</link>
      <guid>https://ruby-china.org/topics/20036</guid>
    </item>
  </channel>
</rss>
