rubinius/rubinius — pull request #1828 by tsion (2012-07-25 04:39:35+00:00)
Title: Fix #inspect, #to_s, and #message for ArgumentError

I noticed some odd behaviour from ArgumentError:

``` irb
>> lambda{|x| x}.call
ArgumentError: ArgumentError
```

Where was the usual descriptive message?

``` irb
>> begin; lambda{|x| x}.call; rescue => e; e.message; end
=> "method '__block__': given 0, expected 1"
```

Apparently, it just didn't make it into `ArgumentError#inspect`.

This patch defines `to_s` rather than `message` on ArgumentError so the custom behaviour gets used by `Exception#inspect` which calls `to_s`.

The second odd thing I noticed:

``` irb
>> ArgumentError.new.message
=> "given , expected "
```

This happened because the existing `ArgumentError#message` didn't properly handle the case where there is neither a normal exception message nor a `@given`/`@expected`/`@method_name` message from the C++ function `Exception::make_argument_error`.

This patch handles that case by calling super when it comes up (so, `Exception#to_s`, which prints the class name if there is no message).

So, now:

``` irb
>> lambda{|x| x}.call
ArgumentError: method '__block__': given 0, expected 1
>> ArgumentError.new.message
=> "ArgumentError"
```

Tell me what you think! Does anything need to change?