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

  • Dopelives

    Dopelives

    30 Temmuz 2009
  • fouseyTUBE

    fouseyTUBE

    21 Mart 2011
  • newreleaseblitz

    newreleasebl

    13 Ocak 2010