我写的经典fizzbuzz代码。
该规范:
describe "can determine fizzbuxx output for" do
it "3" do
expect(Fizzbuzz.nums(3)).to eq "123fizz"
end
end
编码:
class Fizzbuzz
def self.nums(n)
result=""
(1..n).each do |inner|
puts "inner #{inner}"
result << inner
if (inner % 3)==0
result << 'fizz'
end
if (inner % 5)==0
result << 'buzz'
end
end
result
end
end
为什么我会得到\u001
......而不是1
?
Failures:
1) can determine fizzbuxx output for 3
Failure/Error: expect(Fizzbuzz.nums(3)).to eq "123fizz"
expected: "123fizz"
got: "\u0001\u0002\u0003fizz"
(compared using ==)
# ./fizzbuzz_spec.rb:5:in `block (2 levels) in <top (required)>'
它是某种形式的utf-8的问题?