Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 Ruby 有点陌生,我想用字符串替换局部变量。如果我有:
user = "foo" pass = "bar" puts "if you #{user}, you should #{bar}" #prints: if you foo, you should bar
但在我的情况下,字符串是文件中的一行文本,因此在解析时未声明。是否有任何内置功能可以让我赶上这种机制?
string = "if you %{user}, you should %{pass}" string % {user: "foo", pass: "bar"} # => "if you foo, you should bar"