我創建了物件TriggerFillLocalRunAt.
。如果屬性tables_ids是空的,需要將所有的id設定為這個屬性。我想覆寫table_ids的getter。
class TriggersFillLocalRunAt>
attr_reader :tables_id
attr_reader:offset
attr_reader :時區
attr_reader :organ
attr_reader :run_at
def initialize(org, table_ids, offset, timezone, run_at)
@org = org
tables_ids = table_ids
@offset = offset.to_i
@timezone = timezone
@run_at = run_at
end=結束。
def tables_ids=(value)
@tables_ids = value ? value.split(' ').map(& :to_i) : tables_ids_for_subdomain
結束。
def perform
.................
end
end
我創建物件 TriggersFillLocalRunAt.new(org, table_ids, offset, timezone, run_at).執行
where table_ids is null
我的overide getter沒有呼叫,并且@tables_ids是空的。
uj5u.com熱心網友回復:
在呼叫setter時,你總是需要明確地使用self:
def initialize(org, table_ids, offset, timezone, run_at)
@org = org
self.tables_ids = table_ids
@offset = offset.to_i
@timezone = timezone
@run_at = run_at
end
如果你不使用self,你只是簡單地分配了區域變數tables_ids。我還建議你使用關鍵字引數,這樣你就不必記住5個引數的順序:
def initialize( org: , table_ids:, offset:, timezone:, run_at:)
@org = org
self.tables_ids = table_ids
@offset = offset.to_i
@timezone = timezone
@run_at = run_at
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/307009.html
標籤:
