0

我正在尝试在我的 Ruby 应用程序中使用 Redcloth,wrong number of arguments (3 for 2)即使我只有两个参数,它也会给我一个错误。

这是我的代码:

def self.cleanup(string)
  if string == "" || string == nil
    ""
  else

            string = self.iconvert(string, "ascii", "utf8")

    RedCloth.include(RedCloth::Formatters::HTML)
    redcloth = RedCloth.new(string)
    redcloth.html_esc(string)
    string = string.strip
    string = string.gsub(/''/,"\"")
    string = string.gsub(/\r/," ")
    string = string.gsub(/\n/," ")
    string = string.gsub(/\<br \/\>/," ")
    string = string.gsub(/\<br\/\>/," ")
    string = string.gsub(/&nbsp;/," ")
    redcloth.clean_html(string, {})
    string
  end
end

这是源代码:http ://redcloth.rubyforge.org/classes/RedCloth/Formatters/HTML.html#M000052

def clean_html( text, allowed_tags = BASIC_TAGS )
  text.gsub!( /<!\[CDATA\[/, '' )
  text.gsub!( /<(\/*)([A-Za-z]\w*)([^>]*?)(\s?\/?)>/ ) do |m|
  raw = $~
  tag = raw[2].downcase
  if allowed_tags.has_key? tag
    pcs = [tag]
    allowed_tags[tag].each do |prop|
      ['"', "'", ''].each do |q|
        q2 = ( q != '' ? q : '\s' )
        if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
          attrv = $1
          next if (prop == 'src' or prop == 'href') and not attrv =~ %r{^(http|https|ftp):}
          pcs << "#{prop}=\"#{attrv.gsub('"', '\\"')}\""
          break
        end
      end

这是我的日志:

I, [2013-07-16T12:22:53.095073 #12321]  INFO -- : wrong number of arguments (3 for 2)
I, [2013-07-16T12:22:53.095281 #12321]  INFO -- : /home/emai/.rvm/gems/ruby-1.9.3-p448@edmund/gems/RedCloth-4.2.9/lib/redcloth/formatters/base.rb:46:in `method_missing'
4

1 回答 1

0

您收到错误是因为method_missingRedcloth 源文件 (base.rb) 中的定义仅使用两个参数(并且没有 splat 运算符)定义,并且您正在调用带有两个参数的未定义方法,当添加到方法名称时, 导致三个参数被传递给method_missing.

有问题的电话似乎是对 的电话redcloth.clean_html。正如您在评论中指出的那样,clean_html它是一种私有方法,因此您无法通过正常的object.method调用机制访问它。

于 2013-07-17T18:58:40.827 回答