Created
June 6, 2013 13:36
-
-
Save marcinwyszynski/5721525 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
| class Enum | |
| include Enumerable | |
| def initialize(input) | |
| @hash = {} | |
| method = input.is_a?(Array) ? :each_with_index : :each | |
| input.send(method) do |key, value| | |
| @hash[key] = value | |
| self.class.send(:define_method, key.to_sym) { value } | |
| end | |
| freeze | |
| end | |
| def each | |
| @hash.values.each { |v| yield v } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment