返回值我有以下方法(S)下面的類:實例變量在Ruby中
class Ad
def generate
# Find logo
@logo = create_logo(arg1,arg2...)
end
def create_logo(arg1,arg2,..)
#Logic that sets @logo
return @logo
end
end
所以,你可以看到我使用的是@instance_variable作爲返回值和接收的方法值。我相信通過這樣做,方法更具可測性,並且它使代碼變得清晰,但是您認爲這在Ruby中是正確的嗎?
或者這將是更正確的:
class Ad
def generate
# Find logo
create_logo(arg1,arg2...)
end
def create_logo(arg1,arg2,..)
#Logic that sets @logo
end
end
感謝
你在哪裏使用實例變量作爲參數? – Linuxios
好的。我的問題會更像是......一種方法返回實例變量是否正常?或者應該在方法內部修改? –
@Linuxios修改了這個問題。 –