Skip to content

Instantly share code, notes, and snippets.

@duykhoa
Last active August 29, 2015 14:19
Show Gist options
  • Save duykhoa/4022b5ca0676981a3fcf to your computer and use it in GitHub Desktop.
Save duykhoa/4022b5ca0676981a3fcf to your computer and use it in GitHub Desktop.
class Traxex
# st above
def attack
# do st
end
end
class AttackDecorator
def initialize(hero_object)
@hero_object = hero_object
end
def attack
raise NotImplementedError.new("implement in subclass")
end
end
class FrostArrowDecorator < AttackDecorator
def initialize(hero_object)
super(hero_object)
@is_iced_stune_effect = true
end
def attack
stun_for(stun_rate)
@hero_object.attack()
end
end
class MarksmanShipDecorator < AttackDecorator
def initialize(hero_object)
super(hero_object)
@hero_object.damage = marksman_ship_damage
@marksman_ship_effect = true
end
def attack
@hero_object.attack()
aura_damge
end
end
# example using
traxex = Traxex.new(strength: 24, agility: 20, speed: 17)
# normal attack
traxex.attack
# frost arrow attack
traxex_frost_arrow = FrostArrowDecorator.new(traxex)
traxex_frost_arrow.attack
# frost arrow attack with marksman ship
MarksmanShipDecorator.new(traxex_frost_arrow).attack
# complex attack
FirstDecorator.new(SecondDecorator.new(ThirdDecorator.new(FourthDecorator))).attack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment