Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enum.each and Enum#each #3830

Merged
merged 2 commits into from Jan 4, 2017

Conversation

ysbaddaden
Copy link
Contributor

Add Enum.each to iterate the enum constants (and values) as well as Enum#each to iterate flags included in the enum value.

Examples:

enum MyEnum
  One
  Two
end

@[Flags]
enum MyFlags
  One
  Two
  Three
end

MyEnum.each do |member, value|
  # yield One, 0
  # yield Two, 1
end

# note that `None` and `All` aren't iterated
MyFlags.each do |member, value|
  # yield One, 1
  # yield Two, 2
  # yield Three, 3
end

(MyFlags::One | MyFlags::Three).each do |member, value|
  # yield One, 1
  # yield Three, 3
end

@asterite
Copy link
Member

asterite commented Jan 4, 2017

Thank you!

@asterite asterite merged commit 5f515df into crystal-lang:master Jan 4, 2017
@ysbaddaden ysbaddaden deleted the feature-enums-each branch June 27, 2018 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants