Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created August 31, 2012 18:15
Show Gist options
  • Save kmandreza/3556822 to your computer and use it in GitHub Desktop.
Save kmandreza/3556822 to your computer and use it in GitHub Desktop.
8.31.12 SpaceShip class
#Object Oriented Design, Simon Allardice from lynda.com
#Class: SpaceShip
#Attributes: +public name: String
# -private shieldstrength: Integer
#Operations: +fire( ): String
# -reduce shields (Integer)
#Notes: 1. Public Class Spaceship
# 2. Attributes are expressed as instance variables, which are variables that belong to an instance of a class. What this means is that any object created within this class will have their own copy of these variables <--I NEED A VISUAL OF THIS BADLY
# 3. +Public or -Private refers to the visibility level of the features we are coding up.
class Spaceship
#instance variables
@name
@shieldstrength
#methods
def fire
return "Boom!"
end
def reduce_shields(amount)
shield_strength -= amount
end
end
@mockdeep
Copy link

mockdeep commented Sep 3, 2012

should be:

class Spaceship
  def initialize(new_name)
    @name = new_name
    @shield_strength = 10
  end

  def fire
    "Boom!"
  end

  def reduce_shields(amount)
    @shield_strength -= amount
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment