Rails curl syntax

后端 未结 2 883
有刺的猬
有刺的猬 2021-01-14 09:10

I can run the following command from my rails app:

Hash.from_xml(%x{curl -d \"admin=true\" http://localhost:8888} ) rescue nil

now I want t

2条回答
  •  时光说笑
    2021-01-14 10:01

    x = %Q{"admin=true"}
    Hash.from_xml(%x{curl -d "#{x}" http://localhost:8888} ) rescue nil
    

    The %Q{}syntax indicates a quoted string, which is kind of like a "super"/"enhanced" version of a double-quoted string.

    The #{} syntax inside %x{} is called interpolation and it allows to evaluate Ruby code inside a string.

提交回复
热议问题