Issue #11640 has been reported by Kaneko Yuichiro.

----------------------------------------
Bug #11640: [PATHC] Sometime `NameError#message` raises `ArgumentError: malformed format string - %$`
https://bugs.ruby-lang.org/issues/11640

* Author: Kaneko Yuichiro
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-10-30 trunk 52371) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
```ruby
  def test_message_of_name_error
    begin
      Module.new do
        module_function :foo
      end
    rescue => e
      error = e
    end

    assert_match /\Aundefined method `foo' for module `#<Module:.*>'\z/, error.message
  end

# =>

TestException#test_name_error:
ArgumentError: malformed format string - %$
    /Users/yuichirokaneko/ruby/ruby/test/ruby/test_exception.rb:734:in `to_str'
    /Users/yuichirokaneko/ruby/ruby/test/ruby/test_exception.rb:734:in `to_s'
    /Users/yuichirokaneko/ruby/ruby/test/ruby/test_exception.rb:734:in `message'
    /Users/yuichirokaneko/ruby/ruby/test/ruby/test_exception.rb:734:in `test_name_error'
```

I send [PR](https://github.com/ruby/ruby/pull/1077).



-- 
https://bugs.ruby-lang.org/