Skip to content

Instantly share code, notes, and snippets.

@jonsmock
Created May 3, 2012 20:06
Show Gist options
  • Save jonsmock/2588878 to your computer and use it in GitHub Desktop.
Save jonsmock/2588878 to your computer and use it in GitHub Desktop.
Possible solution for place mutation (somewhat functional approach)
# in board initialize
lookup = PlaceLookup.new
lookup.add Buildable.new, Coord.new(3, 4) # coords would be calculated from land hexes
# later
player = Player.new
PlaceLookup.build_at player, Coord.new(3, 4)
PlaceLookup.at Coord.new(3, 4) # => Settlement.new
The PlaceLookup mutates behind the scenes. So potential impl of #build_at is
class PlaceLookup
def build_at player, coord
# when you call build on a Buildable object you get a Settlement.new back
@places[coord] = @places[coord].build player
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment