阅读背景:

获取错误未定义方法`[]'为nil:NilClass(NoMethodError)

来源:互联网 

Here is the code

这是代码

class Tech
  attr_reader :content, :tech_hash
  @tech_hash = Hash.new(0)
  def initialize(content)
    @content = content
    showTech(content)
  end
  def showTech(content)
    content.split.each do |word|
    @tech_hash[word] += 1
    end
    @tech_hash = @tech_hash.sort_by{|k,v| -v}.to_h
    p @tech_hash
  end
end

class Digital
  def analyze()
    File.foreach('test.txt') do |content|
      ob = Tech.new(content)
    end
  end
end

digi = Digital.new()
digi.analyze()
class Tech
  attr_rea



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: