<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>tdxh20 (tdxh20)</title>
    <link>https://ruby-china.org/tdxh20</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>新手问题，关于 attr </title>
      <description>&lt;p&gt;class BookInStock
attr_reader :isbn
attr_accessor :price
def initialize(isbn, price)
&lt;a href="/isbn" class="user-mention" title="@isbn"&gt;&lt;i&gt;@&lt;/i&gt;isbn&lt;/a&gt; = isbn
&lt;a href="/price" class="user-mention" title="@price"&gt;&lt;i&gt;@&lt;/i&gt;price&lt;/a&gt; = Float(price)
end
def price_in_cents
Integer(price*100 + 0.5)
end
def price_in_cents=(cents)
price = cents / 100.0
end&lt;/p&gt;
&lt;h2 id="..."&gt;...&lt;/h2&gt;
&lt;p&gt;end
book = BookInStock.new("isbn1", 33.80)
puts "Price = #{book.price}"
puts "Price in cents = #{book.price_in_cents}"
book.price_in_cents = 1234
puts "Price = #{book.price}"
puts "Price in cents = #{book.price_in_cents}"&lt;/p&gt;

&lt;p&gt;看这段代码，能跑的，但是 price 的值没有赋进去，我知道因为 price = cents / 100.0 没有 写&lt;a href="/price" class="user-mention" title="@price"&gt;&lt;i&gt;@&lt;/i&gt;price&lt;/a&gt;，但是这行能运行的，我想知道这个 price 的值到底赋到哪去了
price 这个变量在 price_in_cents 里没有出现过，那怎么可以用的么  &lt;/p&gt;</description>
      <author>tdxh20</author>
      <pubDate>Fri, 20 Apr 2012 08:10:02 +0800</pubDate>
      <link>https://ruby-china.org/topics/2746</link>
      <guid>https://ruby-china.org/topics/2746</guid>
    </item>
  </channel>
</rss>
