<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>HM (Neo)</title>
    <link>https://ruby-china.org/HM</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>Rails 路由问题请教</title>
      <description>&lt;p&gt;这里是一段 rails app 的日志：&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Started GET "/programs.afasdfasdf" for ::1 at 2023-05-06 14:02:28 +0800
Processing by ProgramsController#index as */*
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;routes.rb&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resources :programs, only: [:index],  do
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;问题:
怎样让 Rails 不忽略“.afasdfasdf”部分，直接报路由错误，Rails 里有可以配置的地方么&lt;/p&gt;</description>
      <author>HM</author>
      <pubDate>Sat, 06 May 2023 14:43:33 +0800</pubDate>
      <link>https://ruby-china.org/topics/43054</link>
      <guid>https://ruby-china.org/topics/43054</guid>
    </item>
    <item>
      <title>attr_accessor 问题探讨</title>
      <description>&lt;p&gt;一段简单的求斐波拉契数列的 ruby 代码，Fibnacci 类中 attr_accessor 方法定义的属性:memo, :index，代码如下&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# 求斐波拉契数列的一个简单方法
class Fibnacci
  attr_accessor :memo, :index
  def initialize
    @memo = {}
    @index = 0
  end


  def fib_pro(n)
    return memo[n] if memo.has_key? n 
    return 1 if n &amp;lt;= 2
    memo[n] = fib_pro(n-1) + fib_pro(n-2) 
  end

  def next
    # index = @index + 1 # 错误用法1
    # index +=1                # 错误用法2
    @index += 1               # 正确用法
    fib_pro(index)
  end
end

obj = Fibnacci.new
puts obj.next
puts obj.next
puts obj.next
puts obj.next
puts obj.next
puts obj.next
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;期望输出&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
1
2
3
5
8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;代码中错误用法 1 得不到正确结果，&lt;a href="/index" class="user-mention" title="@index"&gt;&lt;i&gt;@&lt;/i&gt;index&lt;/a&gt; 值没有更新，
错误用法 2 直接报错：undefined method `+' for nil:NilClass (NoMethodError)
问题：为啥同是 attr_accessor 定义的属性 memo[n] = 可以正常使用，index +=  报错，index = &lt;a href="/index" class="user-mention" title="@index"&gt;&lt;i&gt;@&lt;/i&gt;index&lt;/a&gt; + 1 也不生效
工作中也发现有时候部分 attr_accessor 定义的属性赋值后没被更新，始终没找到根因，求论坛里各路大神指导&lt;/p&gt;</description>
      <author>HM</author>
      <pubDate>Sat, 18 Mar 2023 11:04:40 +0800</pubDate>
      <link>https://ruby-china.org/topics/42947</link>
      <guid>https://ruby-china.org/topics/42947</guid>
    </item>
  </channel>
</rss>
