Last active
December 20, 2015 08:09
-
-
Save rauxalach/6098203 to your computer and use it in GitHub Desktop.
This file contains 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
# encoding: UTF-8 | |
class Heo | |
attr_accessor :tên | |
def initialize(tên) | |
@tên = tên | |
end | |
def xây_nhà | |
case tên | |
when 'út'; @nhà = Nhà.new(Rơm.new) | |
when 'anh nhì'; @nhà = Nhà.new(Gỗ.new) | |
when 'anh cả'; @nhà = Nhà.new(Gạch.new) | |
end | |
end | |
end | |
class Nhà | |
attr_accessor :vật_liệu, :bị_đổ | |
def initialize(vật_liệu) | |
@vật_liệu = vật_liệuend | |
@bị_đổ ||= false | |
end | |
def chịu_được_gió(sức_gió) | |
if @vât_liệu.mức_gió_chịu_được < sức_gió | |
return false | |
else | |
return true | |
end | |
class Sói | |
def thổi(nhà, sức_gió) | |
nhà.bị_đổ = true if nhà.vật_liệu.mức_gió_chịu_được <= sức_gió | |
end | |
endend | |
class VậtLiệu | |
attr_accessor :mức_gió_chịu_được | |
end | |
class Rơm < VậtLiệu | |
def initialize | |
@mức_gió_chịu_được = 1 | |
end | |
end | |
class Gỗ < VậtLiệu | |
def initialize | |
@mức_gió_chịu_được = 2 | |
end | |
end | |
class Gạch < VậtLiệu | |
def initialize | |
@mức_gió_chịu_được = 999 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment