Skip to content

Instantly share code, notes, and snippets.

@studio3104
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save studio3104/d66e335d435e30f36eda to your computer and use it in GitHub Desktop.
Save studio3104/d66e335d435e30f36eda to your computer and use it in GitHub Desktop.
インスタンス変数があったらそれ返してなかったらなんか処理してインスタンス変数に突っ込んでから返すって処理
class Hoge:
def hage(self):
if not '_hage' in self.__dict__.keys():
self._hage = 'hage'
return self._hage
hoge = Hoge()
print hoge.hage()
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