Created
August 18, 2012 13:16
-
-
Save andycamp/3386801 to your computer and use it in GitHub Desktop.
ruby inheritable constants
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 A | |
| SUB_TYPES = %w(bass trout salmon) | |
| def valid_sub_type?(sub_type) | |
| self.class::SUB_TYPES.include? sub_type | |
| end | |
| end | |
| class B < A | |
| SUB_TYPES = %w(whale beaver dog) | |
| end | |
| puts A.new.valid_sub_type?('salmon') | |
| puts A.new.valid_sub_type?('tokyo') | |
| puts B.new.valid_sub_type?('beaver') | |
| puts B.new.valid_sub_type?('duck') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment