読者です 読者をやめる 読者になる 読者になる

悪あがきプログラマー

悪あがきを続けていきたい技術と書評なブログです。トレタでiOSエンジニアやってます。

ERROR NoMethodError: private method `gsub!' called for #<Class:0x10fb60b10>

rails

昔のプロジェクトを立ち上げてみようとしたらエラーが

[2012-02-21 09:52:49] ERROR NoMethodError: private method `gsub!' called for #<Class:0x10fb60b10>
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/htmlutils.rb:16:in `escape'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/httpresponse.rb:232:in `set_error'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/rails-2.2.3/lib/webrick_server.rb:94:in `handle_file'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/rails-2.2.3/lib/webrick_server.rb:73:in `service'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:162:in `start'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:95:in `start'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:92:in `each'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:92:in `start'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:23:in `start'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/webrick/server.rb:82:in `start'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/rails-2.2.3/lib/webrick_server.rb:60:in `dispatch'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/rails-2.2.3/lib/commands/servers/webrick.rb:66
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/activesupport-2.2.3/lib/active_support/dependencies.rb:153:in `require'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/activesupport-2.2.3/lib/active_support/dependencies.rb:521:in `new_constants_in'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/activesupport-2.2.3/lib/active_support/dependencies.rb:153:in `require'
     /Users/yoonchulkoh/.rvm/gems/ruby-1.8.6-p420@rails-2.2.3/gems/rails-2.2.3/lib/commands/server.rb:49
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
     /Users/yoonchulkoh/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
     script/server:3

環境は、
ruby1.8.6
rails2.2.3

なんだかwebrickのバグだとか。

css - Ruby on Rails: odd stylesheet issue - Stack Overflow
ERROR NoMethodError: private method `gsub!' called - Ruby Forum

lib/ruby/1.8/webrick/htmlutils.rbのstring.dupを以下のように書き換えればOK

module WEBrick
  module HTMLUtils

    def escape(string)
      str = string ? string.to_s.dup : ""
      str.gsub!(/&/n, '&amp;')
      str.gsub!(/\"/n, '&quot;')
      str.gsub!(/>/n, '&gt;')
      str.gsub!(/</n, '&lt;')
      str
    end
    module_function :escape

  end
end

ところでrubyのシンタックスハイライトまだー?