SORU
23 EYLÜL 2011, Cuma


Ruby Koanları bu test_changing_hashes bonus sorunun cevabı nedir?

** 5, Bölüm about_hashes.rb aşağıdaki kodu ve yorum içerir:

def test_changing_hashes
    hash = { :one => "uno", :two => "dos" }
    hash[:one] = "eins"

    expected = { :one => "eins", :two => "dos" }
    assert_equal true, expected == hash

    # Bonus Question: Why was "expected" broken out into a variable
    # rather than used as a literal?
end

Açıklama bonus sorusunun cevabını anlayamadığım - aslında önerdikleri değiştirme yapmayı denedim ve sonuç aynı. Çözebilirim tüm okunabilir olduğunu, ama başka bir yerde bu eğitimde seslendi gibi genel programlama öneri göremiyorum.

(Bu zaten bir yere cevap olacak bir şey gibi geliyor biliyorum, ama hiçbir yetkili kazabilirim.)

CEVAP
23 EYLÜL 2011, Cuma


Böyle bir şey kullanamazsın, çünkü:

assert_equal { :one => "eins", :two => "dos" }, hash

Ruby düşünüyor { ... } bir blok. Yani, "bir değişken içine dışarı kırık" ama sen her zaman assert_equal({ :one => "eins", :two => "dos" }, hash) . kullanmak gerekir

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • CasinoRoyaleMovie's channel

    CasinoRoyale

    1 AĞUSTOS 2006
  • Phymec

    Phymec

    18 Temmuz 2009
  • TheJoeycool2010

    TheJoeycool2

    12 Temmuz 2010