https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-04-13T03:51:18ZRuby Issue Tracking SystemRuby master - Feature #8262: Confusing "undefined method" exception when using - operator on a stringhttps://bugs.ruby-lang.org/issues/8262?journal_id=385032013-04-13T03:51:18Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>The thing is that the name of the "unary minus" method is "-@", and what you did was send that to "5".</p>
<pre><code>42.send(:-@) # => -42
"5".send(:-@) # => same as -"5", i.e. NoMethodError: undefined method `-@' for "5":String
</code></pre>
<p>I agree it's not super clear, but it is correct and has the advantage of teaching people what the method for unary minus is, if they wanted to define one for example.</p>
<p>What would you have liked to read instead as an error message?</p>
<p>(moving to feature)</p> Ruby master - Feature #8262: Confusing "undefined method" exception when using - operator on a stringhttps://bugs.ruby-lang.org/issues/8262?journal_id=385042013-04-13T03:51:43Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li></ul> Ruby master - Feature #8262: Confusing "undefined method" exception when using - operator on a stringhttps://bugs.ruby-lang.org/issues/8262?journal_id=387122013-04-19T02:10:12Zajack (Jack Weeden)jack@ajack.org
<ul></ul><p>OK, this makes perfect sense now! I'd never come across the "-@" syntax for unary operators. Thanks!</p> Ruby master - Feature #8262: Confusing "undefined method" exception when using - operator on a stringhttps://bugs.ruby-lang.org/issues/8262?journal_id=387132013-04-19T02:22:07Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Perfect. I'll close this then, unless someone comes up with a better proposal.</p>