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

Enum.to_sym for regular enums. #4598

Closed
wants to merge 1 commit into from
Closed

Conversation

akzhan
Copy link
Contributor

@akzhan akzhan commented Jun 20, 2017

It's useful to write expressions like that:

value = Color::Red

case value.to_sym
  when :red
     "wine"
  when :green
     "absinthe"
end

I wanted it to simplify expressions like

when Cldr::Core::CalendarSystem::Lunisolar
   "oh no"
end

P.S.: There is no easy way to apply this to flags.

@Arcovion
Copy link

Simply use: (code here)

enum Color
  Red
  Green
end

value = Color::Red

case value
when .red?
  puts "wine"
when .green?
  puts "absinthe"
end

Using symbols sacrifices type safety: you can easily misspell a symbol, but methods are always looked up and checked.

@akzhan
Copy link
Contributor Author

akzhan commented Jun 20, 2017

@Arcovion wow, thanks. Doesn't know about when .proc syntax :)

@akzhan akzhan closed this Jun 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants