-
Notifications
You must be signed in to change notification settings - Fork 23
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
values: prepend superclass values #29
Merged
+104
−3
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0a9bed3
values: prepend superclass values
gi aa8415e
values: add specs to test more superclass levels
gi cb8f9de
rubocop: exclude spec from Metrics/BlockLength
gi 35a2d7b
values: replace rescue with type check on superclass call
gi 1544254
readme/changlog: updated with `values` superclass behavior
gi 95aa4fe
Merge remote-tracking branch 'base/master' into issue-27/subclass-values
gi da79681
changelog: subsume 0.8.1 into 0.9.0
gi 7bac3c1
readme: update inheritance behavior examples
gi 6673835
values: rename result variable to not shadow method name
gi 5031e6f
version: bump to 0.9.0
gi 0c0e4a0
upgrading: add new file with upgrading implementation details
gi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Upgrading Ruby::Enum | ||
|
||
## Upgrading to >= 0.9.0 | ||
|
||
### Inheritance & `Ruby::Enum.values` | ||
|
||
This only applies to classes that inherit from another which is a `Ruby::Enum`. | ||
|
||
Prior to version `0.9.0`, the `values` class method would enumerate only the | ||
values defined in the class. | ||
|
||
As of version `0.9.0`, the `values` class method enumerates values defined in | ||
the entire class heirarchy, ancestors first. | ||
|
||
``` ruby | ||
class PrimaryColors | ||
include Ruby::Enum | ||
|
||
define :RED, 'RED' | ||
define :GREEN, 'GREEN' | ||
define :BLUE, 'BLUE' | ||
end | ||
|
||
class RainbowColors < PrimaryColors | ||
define :ORANGE, 'ORANGE' | ||
define :YELLOW, 'YELLOW' | ||
define :INIDGO, 'INIDGO' | ||
define :VIOLET, 'VIOLET' | ||
end | ||
``` | ||
|
||
`gem 'ruby-enum', '< 0.9.0'` | ||
|
||
``` ruby | ||
RainbowColors.values # ['ORANGE', 'YELLOW', 'INIDGO', 'VIOLET'] | ||
``` | ||
|
||
`gem 'ruby-enum', '>= 0.9.0'` | ||
|
||
``` ruby | ||
RainbowColors.values # ['RED', 'ORANGE', 'YELLOW', 'GREEN', 'BLUE', 'INIDGO', 'VIOLET'] | ||
``` | ||
|
||
See [#29](https://github.com/dblock/ruby-enum/pull/29) for more information. |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Ruby | ||
module Enum | ||
VERSION = '0.8.1' | ||
VERSION = '0.9.0' | ||
end | ||
end |
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example is super clear, this works.
I do have a question. In the scenario with colors inheritance is the wrong object oriented pattern to use. Rainbow colors don't "inherit" primary colors, they are a combination of primary colors and other colors. In this case we would want a module and mixins. Should we allow
class PrimaryColors
bemodule PrimaryColors
,extend Ruby::Enum
, theninclude PrimaryColors
intoRainbowColors
or something like that? ... for another PR.Maybe there's a better OOO example for README that we can use in a separate update? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Semantically, it makes more sense to
include
thePrimaryColors
in theRainbowColors
class instead of inheriting them.Though, I see this is a minor implementation detail. Defining an enum doesn't actually create an instance of that class:
Colors::RED
isn't an instance ofRuby::Enum
orColors
. It's aString
orSymbol
.There's little difference between inheriting from a class and including a module other than the Ruby semantics. Both options include the base/included class in the class hierarchy.
Regardless, I think this could be an update for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100%