Skip to content

Instantly share code, notes, and snippets.

@marcinwyszynski
Created June 6, 2013 13:36
Show Gist options
  • Select an option

  • Save marcinwyszynski/5721525 to your computer and use it in GitHub Desktop.

Select an option

Save marcinwyszynski/5721525 to your computer and use it in GitHub Desktop.
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