Skip to content

Instantly share code, notes, and snippets.

@benkoshy
Created April 23, 2017 00:59
Show Gist options
  • Select an option

  • Save benkoshy/e18ac7ec5b46b0dc05666c3fd4b6d570 to your computer and use it in GitHub Desktop.

Select an option

Save benkoshy/e18ac7ec5b46b0dc05666c3fd4b6d570 to your computer and use it in GitHub Desktop.
OOP lesson - duck typing 1
# the reader must please forgive me for
# the army analogy. I could not think of
# any other given the 5 seconds I devoted
def ready_weapon(weapon)
    case weapon
    when MachineGun
        weapon.remove_safety_lock
        weapon.load_bullets        
    when Missile
        weapon.check_for_blue_on_blue
        weapon.ensure_laser_is_working
        weapon.obtain_target
    when ApacheHelicopter
        weapon.fuel
        weapon.load_cannons
    when F16
        weapon.replace_old_parts
        weapon.ensure_enging_is_oiled
    end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment