exercise_spec.rb:3:在`<top(required)=“”>':uninitialized constant ArrayModifier(NameError)

时间:2016-07-29 15:38:27

标签: ruby-on-rails ruby

我正在研究类中的ruby循环,我似乎无法通过此名称错误。如果这个问题在其他地方,我道歉,但我发现的问题并不是非常具体。下面是代码:

class StringModifier
    attr_accessor :array

    def initialize(array)
        @array = array
    end

    def exclaim
        array.each do |element|
            array
            "#{element}!"
        end
    end
 end

返回以下错误:

exercise_spec.rb:3:in `<top (required)>': uninitialized constant ArrayModifier (NameError)

Rspec的:

describe ArrayModifier do
  before do 
    @array = ["Roxanne", "Put on the red light", "Roxanne", "Put on the red light"]
  end

  describe '#exclaim' do
    it "adds an exclamation mark to each element" do
      exclaimed = ArrayModifier.new(@array).exclaim
      expect(exclaimed).to eq(["Roxanne!", "Put on the red light!", "Roxanne!", "Put on the red light!"])
    end

    it "doesn't modify the original array" do
      original = @array.dup
      exclaimed = ArrayModifier.new(@array).exclaim
      expect(@array).to eq(original)
    end
  end

0 个答案:

没有答案