<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Thomas (Thomas)</title>
    <link>https://ruby-china.org/Thomas</link>
    <description/>
    <language>en-us</language>
    <item>
      <title>《Ruby 基础教程 第 5 版》P96,代码清单 8.6 中运行出现 bug</title>
      <description>&lt;p&gt;class Point
        attr_accessor:x,:y
        protected :x=,:y=&lt;/p&gt;

&lt;p&gt;def initialize(x=0.0,y=0.0)
                &lt;a href="/x" class="user-mention" title="@x"&gt;&lt;i&gt;@&lt;/i&gt;x&lt;/a&gt;,&lt;a href="/y" class="user-mention" title="@y"&gt;&lt;i&gt;@&lt;/i&gt;y&lt;/a&gt; = x,y
        end&lt;/p&gt;

&lt;p&gt;def swap(other)
                temp_x,temp_y=&lt;a href="/x" class="user-mention" title="@x"&gt;&lt;i&gt;@&lt;/i&gt;x&lt;/a&gt;,&lt;a href="/y" class="user-mention" title="@y"&gt;&lt;i&gt;@&lt;/i&gt;y&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="/x" class="user-mention" title="@x"&gt;&lt;i&gt;@&lt;/i&gt;x&lt;/a&gt;,&lt;a href="/y" class="user-mention" title="@y"&gt;&lt;i&gt;@&lt;/i&gt;y&lt;/a&gt;=other.x,other.y&lt;/p&gt;

&lt;p&gt;other.x,other.y=temp_x,temp_y
                return self&lt;/p&gt;

&lt;p&gt;end&lt;/p&gt;

&lt;p&gt;end&lt;/p&gt;

&lt;p&gt;p0=Point.new
p1=Point.new(1.0,2.0)&lt;/p&gt;

&lt;p&gt;p0.swap(p1)&lt;/p&gt;

&lt;p&gt;在 Mac 运行的时候，提示：
Traceback (most recent call last):
    1: from point.rb:24:in &lt;code&gt;&amp;lt;main&amp;gt;'
point.rb:9:in&lt;/code&gt;swap': wrong number of arguments (given 0, expected 1) (ArgumentError)&lt;/p&gt;

&lt;p&gt;指出传入的参数为 0，但是&lt;a href="/x" class="user-mention" title="@x"&gt;&lt;i&gt;@&lt;/i&gt;x&lt;/a&gt;,&lt;a href="/y" class="user-mention" title="@y"&gt;&lt;i&gt;@&lt;/i&gt;y&lt;/a&gt;=other.x,other.y 中，other.x,other.y 这样就不算参数了？需要如何去修改这个代码？  &lt;/p&gt;

&lt;p&gt;新手不懂，麻烦告知。谢谢&lt;/p&gt;</description>
      <author>Thomas</author>
      <pubDate>Sat, 06 Apr 2019 23:50:07 +0800</pubDate>
      <link>https://ruby-china.org/topics/38354</link>
      <guid>https://ruby-china.org/topics/38354</guid>
    </item>
  </channel>
</rss>
