Created
July 22, 2011 16:53
-
-
Save practicingruby/1099844 to your computer and use it in GitHub Desktop.
foo.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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