Skip to content

Instantly share code, notes, and snippets.

@a-suenami
Last active March 18, 2019 12:21
Show Gist options
  • Save a-suenami/3b69fff0715977eb27eeea267ee6fb6e to your computer and use it in GitHub Desktop.
Save a-suenami/3b69fff0715977eb27eeea267ee6fb6e to your computer and use it in GitHub Desktop.
class Person # エンティティ
attr_reader :name, :yakiniku_treatment_type
def initialize(name, yakiniku_treatment_type, credit_card_number, cash_amount)
@name = Person::Name.new(name)
@yakiniku_treatment_type = Person::YakinikuTreatmentType.new(yakiniku_treatment_type)
end
def 焼肉を奢る
@yakiniku_treatment_type.奢る
end
end
class Person::Name # バリューオブジェクト
def initialize(name)
@name = name
end
def to_s
@name
end
end
class Person::Wallet
def initialize(amount, credit_card)
end
end
class Person::YakinikuTreatmentType # バリューオブジェクト(JavaとかだったらEnumにすれば楽)
CASH_ONLY = 1 # 現金のみ、現金が足りなければ奢らない
CREDIT_CARD_ONLY = 2 # クレジットカードのみ、限度額に達した場合は奢らない
CASH_FIRST = 3 # 財布の中に現金が足りれば現金、そうでなければクレジットカード
def initialize(value)
@value = value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment