, ben internette sörf bu kodu koştu: Ben events.map(&:name)
çalışır nasıl özellikle ilgilendiğim şeyHarita (& isim) bu Ruby kodunda ne yapar? biraz daha iyi Ruby anlamaya çalışırken
require 'rubygems'
require 'activeresource'
ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/events.log")
class Event < ActiveResource::Base
self.site = "http://localhost:3000"
end
events = Event.find(:all)
puts events.map(&:name)
e = Event.find(1)
e.price = 20.00
e.save
e = Event.create(:name => "Shortest event evar!",
:starts_at => 1.second.ago,
:capacity => 25,
:price => 10.00)
e.destroy
? Olayların bir dizi olduğunu ve böylece harita yöntemini çağırdığını görüyorum. Şimdi sorum şu, oluşturulan haritaya aktarılan blok nerede? Bu sembolün adı nedir? Nasıl çalıştığını anlamaya çalışıyorum.
Bu, * yedi * farklı sorunun tam bir kopyasıdır. Ve inanın bana, Ruby son 3 hafta içinde bu kadar değişmedi, bu yüzden cevaplar muhtemelen aynı olacak: http://StackOverflow.Com/questions/99318/, http://StackOverflow.Com/questions/1217088 /, http://StackOverflow.Com/questions/1792683/, http://StackOverflow.Com/questions/1961030/, http://StackOverflow.Com/questions/2096975/, http://StackOverflow.Com/questions/2211751 /, http://StackOverflow.Com/questions/2259775/. –