Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
だから、私はRubyクラスの演算子+を定義しようとしています。+=
+
+=
class A def +(x) end def +=(x) end end
Ruby は を好みますが を好み+ませ+=ん。このエラーが発生します。
構文エラー、予期しない「=」、「;」が必要です または '\n'
私は何を間違えましたか?
Rubyで代入演算子をオーバーロードすることはできません
演算子のオーバーロード - Ruby
Youra += bは次のように解釈され、演算子a = a + bのみが使用されます。演算子も+定義する必要はありません+=
a += b
a = a + b