Permalink
Browse files

Reworded question.

  • Loading branch information...
1 parent 56206e0 commit fbd36f6b0d317045f8f371c3ab6fdb335b8f42aa @jimweirich jimweirich committed Aug 16, 2010
Showing with 12 additions and 12 deletions.
  1. +12 −12 src/about_constants.rb
View
@@ -20,7 +20,7 @@ def test_nested_constants_are_referenced_by_their_complete_path
end
# ------------------------------------------------------------------
-
+
class Animal
LEGS = 4
def legs_in_animal
@@ -33,25 +33,25 @@ def legs_in_nested_animal
end
end
end
-
+
def test_nested_classes_inherit_constants_from_enclosing_classes
- assert_equal __(4), Animal::NestedAnimal.new.legs_in_nested_animal
+ assert_equal __(4), Animal::NestedAnimal.new.legs_in_nested_animal
end
# ------------------------------------------------------------------
-
+
class Reptile < Animal
def legs_in_reptile
LEGS
end
end
-
+
def test_subclasses_inherit_constants_from_parent_classes
assert_equal __(4), Reptile.new.legs_in_reptile
end
-
+
# ------------------------------------------------------------------
-
+
class MyAnimals
LEGS = 2
@@ -61,16 +61,16 @@ def legs_in_bird
end
end
end
-
+
def test_who_wins_with_both_nested_and_inherited_constants
assert_equal __(2), MyAnimals::Bird.new.legs_in_bird
end
-
+
# QUESTION: Which has precedence: The constant in the lexical scope,
# or the constant from the inheritance heirarachy?
-
+
# ------------------------------------------------------------------
-
+
class MyAnimals::Oyster < Animal
def legs_in_oyster
LEGS
@@ -83,5 +83,5 @@ def test_who_wins_with_explicit_scoping_on_class_definition
# QUESTION: Now Which has precedence: The constant in the lexical
# scope, or the constant from the inheritance heirarachy? Why is it
- # different?
+ # different than the previous answer?
end

0 comments on commit fbd36f6

Please sign in to comment.