Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following question:

person = "John", building = "Big Tower"

I want to use Ruby's string interpolation to produce the following:

"My friend John owns the building Big Tower"

Is this the correct answer:

puts "My friend #{person} owns the building #{building}"

??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
248 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you intended the variable assignment to be Ruby code, then it is wrong. It should be

person = "John"; building = "Big Tower"

or

person, building = "John", "Big Tower"

And for the question, yes, except that interpolation is a feature of Ruby, not Rails. Please be respectful to plain Ruby and its developers, and don't confuse it with Rails. Rails is only a framework built on top of Ruby. Rails is not the only use of Ruby.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...