Nin*_*a2k -1 ruby string-literals
以下代码生成错误,我看不到问题.有人可以帮忙吗?
customer_array = [‘Ken’,’William’,’Catherine’,’Mark’,’Steve’,’Sam’]
customer_hash = {
‘Ken’ => ‘Fiction’,
‘William’ => ‘Mystery’,
‘Catherine’ => ‘Computer’,
‘Mark’ => ‘Fiction’,
‘Steve’ => ‘Sports’,
‘Sam’ => ‘Fiction’
}
# => customer_array.rb:6: syntax error, unexpected tSTRING_BEG , expecting '}'
# 'William' => 'Mystery'
# ^
Run Code Online (Sandbox Code Playgroud)
问题似乎与那些奇怪的背引言有关.试试这个:
customer_array = ["Ken","William","Catherine","Mark","Steve","Sam"]
customer_hash = {
"Ken" => "Fiction",
"William" => "Mystery",
"Catherine" => "Computer",
"Mark" => "Fiction",
"Steve" => "Sports",
"Sam" => "Fiction"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
93 次 |
| 最近记录: |