2009-09-10 20 views
0

另外,「self.send attr」是做什麼的? attr是否被認爲是ActiveEngineer類的私有實例變量?在Ruby邏輯方面,這段代碼是否還有其他問題?如果申請人課程「要求'mad_skills'」或「包含'mad_skills'」?

class Applicant < ActiveEngineer 

    require 'ruby' 
    require 'mad_skills' 
    require 'oo_design' 
    require 'mysql' 

    validates :bachelors_degree 

    def qualified? 
    [:smart, :highly_productive, :curious, :driven, :team_player ].all? do 
|attr| 
     self.send attr 
    end 
    end 
end 

class Employer 
    include TopTalent 
    has_millions :subscribers, :include=>:mostly_women 
    has_many :profits, :revenue 
    has_many :recent_press, :through=>[:today_show, :good_morning_america, 
            :new_york_times, :oprah_magazine] 
    belongs_to :south_park_sf 
    has_many :employees, :limit=>10 

    def apply(you) 
    unless you.build_successful_startups 
     raise "Not wanted" 
    end 
    unless you.enjoy_working_at_scale 
     raise "Don't bother" 
    end 
    end 

    def work 
    with small_team do 
     our_offerings.extend you 
     subscribers.send :thrill 
     [:scaling, :recommendation_engines, : ].each do |challenge| 
     assert intellectual_challenges.include? challenge 
     end 
     %w(analytics ui collaborative_filtering scraping).each{|task| 
task.build } 
    end 
    end 

end 

def to_apply 
    include CoverLetter 
    include Resume 
end 
+0

任何認爲學位是必不可少的潛在僱主可能都不值得爲之工作。 「代碼」在幾個地方有嫌疑,足以再次表明他們沒有得到它。極客們對這樣的事情有幽默感,但這並沒有打到它。究竟是什麼「:包括=>:mostly_women」應該試圖說,我想知道? – 2009-09-10 16:06:15

+0

我認爲「:include =>:mostly_women」意思是說,無論這個僱主做什麼產品都有數百萬訂閱者,其中大多數是女性。 – uzo 2009-09-10 16:23:15

回答

3

require 'mad_skills'加載在mad_skills.rb代碼(或它取決於哪一個存在加載mad_skills.so/.dll)。在能夠使用該文件中定義的類,方法等之前,您需要一個文件(儘管在rails中嘗試訪問與文件具有相同名稱的類時會自動加載文件)。將需求放在類定義中,根本不會改變它的行爲(即將它放在文件的頂部並不會產生影響)。

include MadSkills取模塊MadSkills幷包括它變成Applicant的繼承的鏈,即它使MadSkills可用的Applicant實例的所有方法。

self.send attr使用在attr on self中指定的名稱執行方法並返回其返回值。例如。 attr = "hello"; self.send(attr)將與self.hello相同。在這種情況下,它會執行方法smart,highly_productive,curious,driventeam_player,並檢查它們全部是否返回true。

+0

很好的解釋。謝謝。 – uzo 2009-09-10 16:24:36