Skip to content

Commit

Permalink
Add to Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
veelenga committed Oct 2, 2017
1 parent 79729d9 commit dda2ef5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ The goal is to have a set of [GOF patterns](http://www.blackwasp.co.uk/gofpatter
- [Composite](structural/composite.cr)
- [Decorator](structural/decorator.cr)
- [Facade](structural/facade.cr)
- [Flyweight](structural/flyweight.cr)

## Contribution

Expand Down
21 changes: 17 additions & 4 deletions structural/flyweight.cr
Expand Up @@ -37,11 +37,9 @@ class Forest

def get_tree(species : String)
if @trees.has_key?(species)
return @trees[species]
@trees[species]
else
tree = Tree.new(species)
@trees[species] = tree
return tree
Tree.new(species).tap { |tree| @trees[species] = tree }
end
end

Expand All @@ -66,3 +64,18 @@ forest.get_tree("acacia").draw_at({33, 49})
forest.get_tree("magnolia").draw_at({0, 0})
puts "-----------------------"
puts "Total instances created: #{forest.tot_instances}"

# Drawing birch at {5, 6}
# Drawing acacia at {3, 1}
# Drawing magnolia at {15, 86}
# Drawing birch at {8, 15}
# Drawing acacia at {18, 4}
# Drawing baobab at {1, 41}
# Drawing magnolia at {80, 50}
# Drawing acacia at {22, 3}
# Drawing birch at {1, 42}
# Drawing baobab at {15, 7}
# Drawing acacia at {33, 49}
# Drawing magnolia at {0, 0}
# -----------------------
# Total instances created: 4

0 comments on commit dda2ef5

Please sign in to comment.