SORU
29 EYLÜL 2008, PAZARTESİ


Bir dize enterpolasyon bir normal ifade içine

Ruby benim normal ifade içine bir dize değeri yerine ihtiyacım var. Bir kolay yolu bunu yapmak için vardır? Örneğin:

foo = "0.0.0.0"
goo = "here is some other stuff 0.0.0.0" 
if goo =~ /value of foo here dynamically/
  puts "success!"
end

CEVAP
29 EYLÜL 2008, PAZARTESİ


Dize ekleme gibi aynı.

if goo =~ /#{Regexp.quote(foo)}/
#...

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • уσ ρℓz sυв ιℓℓ sυв вαcқ

    уσ ρℓz

    14 EKİM 2010
  • NYCarspotter

    NYCarspotter

    26 EYLÜL 2011
  • Qmusic Romania

    Qmusic Roman

    8 Temmuz 2011