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

  • Philip DeFranco

    Philip DeFra

    16 EYLÜL 2006
  • Photoshop Training Channel

    Photoshop Tr

    13 Temmuz 2012
  • Rayone GB

    Rayone GB

    14 Temmuz 2007