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

  • Ben Vivona

    Ben Vivona

    24 Ocak 2010
  • DRDAnimation

    DRDAnimation

    28 EYLÜL 2012
  • hitcreatormusic2

    hitcreatormu

    21 Mayıs 2010