Last active
August 29, 2015 14:19
インスタンス変数があったらそれ返してなかったらなんか処理してインスタンス変数に突っ込んでから返すって処理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge: | |
def hage(self): | |
if not '_hage' in self.__dict__.keys(): | |
self._hage = 'hage' | |
return self._hage | |
hoge = Hoge() | |
print hoge.hage() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge | |
def hage | |
@hage ||= 'hage' | |
end | |
end | |
hoge = Hoge.new | |
p hoge.hage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment