这是我的代码
operator_prompt: >
What operation would you like to perform?
1) add
2) subtract
3) multiple
4) divide
这是我的错误消息
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:377:in `parse': (calculator_messages.yml): could not find expected ':' while scanning a simple key at line 14 column 1 (Psych::SyntaxError)
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:377:in `parse_stream'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:325:in `parse'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:252:in `load'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:471:in `block in load_file'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:471:in `open'
from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:471:in `load_file'
from calculator.rb:2:in `<main>'
我不知道问题是什么。看起来我在YAML中使用的多行字符串完全符合我的要求。
答案 0 :(得分:3)
你应该折叠折叠的多行标量至少一个位置。如果要保留标量中的新行,请使用|
:
operator_prompt: |
What operation would you like to perform?
1) add
2) subtract
3) multiple
4) divide