Skip to content

Instantly share code, notes, and snippets.

View StefanReindl's full-sized avatar

Stefan Reindl StefanReindl

View GitHub Profile
@StefanReindl
StefanReindl / SiegeEngine.rb
Last active August 29, 2015 14:02
Warcraft3 Barracks, SiegeEngine and Unit files
class SiegeEngine < Unit
attr_reader :health_points, :attack_power
def initialize
@health_points = 400
@attack_power = 50
end
def can_attack?(enemy_unit)
enemy_unit.class == SiegeEngine || Barracks

Self

self - is what's called a reflective method - refers to the instance on which it is called.

  • self.variable refers to the most current attribute of that object
    • useful when you are overwriting or changing variables often.
  • Calling @variable instead of self.variable will return the original instance variable defined in the class.
  • self.method is a Class Method - in this case, 'self' refers to the Class itself
    • identical to writing Class_Name.method (which you shouldn't do inside a Class)

Two uses for 'self':

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@StefanReindl
StefanReindl / game_data.rb
Created June 7, 2014 01:39
Math Game - working, with game restart
@player_lives = {
Player1: 3,
Player2: 3
}
@player_scores = {
Player1: 0,
Player2: 0
}