Last active
August 29, 2015 14:05
-
-
Save TrevorS/55c3a8a4151c9b55732e to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env ruby | |
| # encoding: utf-8 | |
| class Counters | |
| def initialize | |
| @h = Hash.new(0) | |
| end | |
| def increment(key, value = 1) | |
| @h[key] += value | |
| end | |
| def print | |
| puts @h.inspect | |
| end | |
| end | |
| c = Counters.new | |
| c.increment(:a) | |
| c.increment(:a, 1) | |
| c.increment(:b, 3) | |
| c.print | |
| # {:a=>2, :b=>3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good,man.