SORU
1 AĞUSTOS 2009, CUMARTESİ


Göster(&:adı Ruby anlamı nedir?

a RailsCast bu kodu buldum:

def tag_names
  @tag_names || tags.map(&:name).join(' ')
end

map(&:name) (&:name) ne anlama geliyor?

CEVAP
1 AĞUSTOS 2009, CUMARTESİ


tags.map(&:name.to_proc).join(' ') steno

Eğer foo bir nesne ile to_proc yöntem, daha sonra geçmek için bir yöntem olarak &foo, çağrı foo.to_proc ve kullanan olarak yöntemin blok.

Symbol#to_proc Bu yöntem aslında ActiveSupport tarafından eklendi ama Ruby 1.8.7 entegre olmuştur. Bu uygulanması

class Symbol
  def to_proc
    Proc.new do |obj, *args|
      obj.send self, *args
    end
  end
end

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Alexey - servant of Christ

    Alexey - ser

    15 EYLÜL 2007
  • Blu animations and other videos

    Blu animatio

    15 HAZİRAN 2007
  • MofoHifi Records

    MofoHifi Rec

    15 HAZİRAN 2006