Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created February 9, 2013 14:29
Show Gist options
  • Save Shinpeim/4745443 to your computer and use it in GitHub Desktop.
Save Shinpeim/4745443 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
class Player
attr_reader :position
def initialize(position)
@position = position
end
def move(direction)
case direction
when :up
@position[:y] -= 10
when :down
@position[:y] += 10
when :left
@position[:x] -= 10
when :right
@position[:x] += 10
end
end
end
player = Player.new(:x => 100, :y => 100)
player.move(:up)
p player.position # => {:x => 100, :y => 90}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment