Ruby: Merging variables in to a string

前端 未结 7 950
[愿得一人]
[愿得一人] 2020-12-02 10:23

I\'m looking for a better way to merge variables into a string, in Ruby.

For example if the string is something like:

\"The animal action<

7条回答
  •  独厮守ぢ
    2020-12-02 10:54

    You can use it with your local variables, like this:

    @animal = "Dog"
    @action = "licks"
    @second_animal = "Bird"

    "The #{@animal} #{@action} the #{@second_animal}"

    the output would be: "The Dog licks the Bird"

提交回复
热议问题