Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created July 22, 2011 16:53
Show Gist options
  • Select an option

  • Save practicingruby/1099844 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/1099844 to your computer and use it in GitHub Desktop.
foo.rb
class Point
def initialize(x,y)
@x, @y = x, y
end
end
module Positionable
attr_accessor :map
def neighbors
# do something with map and @x and @y
end
end
class Map
def initialize(width, height)
@width = width
@height = height
end
def point(x,y)
Point.new(x,y).tap do |point|
point.extend(Positionable)
point.map = self
end
end
def random_point
point(rand(@width), rand(@height))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment