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 Stringクラス、特に+メソッドを変更しようとしています。次のような特定の文字列を返すようにしたい
"a" + "b" => "custom_result"
これが私が持っているものです:
class String def +(a) "custom_result" end end
このファイルをirbで要求しようとすると、プロンプトに「custom_result」が表示され、何も実行できません。何か案は?
IRb はこのStringクラスを使用して、結果を出力し、入力内容を解析します。それをいじると、IRb が壊れますが、それはそれほど驚くべきことではありません。
String