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

  • Fraser Raft

    Fraser Raft

    9 Mart 2010
  • hans peder sahl

    hans peder s

    22 Temmuz 2009
  • Joshua Benedict

    Joshua Bened

    26 EKİM 2013