name.length.to_s的ruby练习

时间:2013-08-27 16:13:01

标签: ruby variable-length

书中的练习说我应该单独询问名字,然后得到名字长度。我被困在第8行?这就是我应该做的名字吗?

    puts "What\'s your first name?"
    first = gets.chomp
    puts "What\'s your middle name?"
    middle = gets.chomp
    puts "What\'s your last name?"
    last = gets.chomp
    puts "So, your full name is #{first} #{middle} #{last}." 
    name = # {first} #{middle} #{last}
    puts "Did you know that are + #{name.length.t_s} + characters "
    puts "in your + name + "

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

应该是(使用ruby string embedding):

name = "#{first} #{middle} #{last}"

http://www.ruby-doc.org/core-2.0/String.html