1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
5 class AboutConstants < EdgeCase::Koan
9 def test_nested_constants_may_also_be_referenced_with_relative_paths
13 def test_top_level_constants_are_referenced_by_double_colons
17 def test_nested_constants_are_referenced_by_their_complete_path
18 assert_equal __, AboutConstants::C
19 assert_equal __, ::AboutConstants::C
22 # ------------------------------------------------------------------
31 def legs_in_nested_animal
37 def test_nested_classes_inherit_constants_from_enclosing_classes
38 assert_equal __, Animal::NestedAnimal.new.legs_in_nested_animal
41 # ------------------------------------------------------------------
43 class Reptile < Animal
49 def test_subclasses_inherit_constants_from_parent_classes
50 assert_equal __, Reptile.new.legs_in_reptile
53 # ------------------------------------------------------------------
65 def test_who_wins_with_both_nested_and_inherited_constants
66 assert_equal __, MyAnimals::Bird.new.legs_in_bird
69 # QUESTION: Which has precedence: The constant in the lexical scope,
70 # or the constant from the inheritance hierarchy?
72 # ------------------------------------------------------------------
74 class MyAnimals::Oyster < Animal
80 def test_who_wins_with_explicit_scoping_on_class_definition
81 assert_equal __, MyAnimals::Oyster.new.legs_in_oyster
84 # QUESTION: Now which has precedence: The constant in the lexical
85 # scope, or the constant from the inheritance hierarchy? Why is it
86 # different than the previous answer?