mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Reworded question.
This commit is contained in:
@@ -20,7 +20,7 @@ class AboutConstants < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
class Animal
|
class Animal
|
||||||
LEGS = 4
|
LEGS = 4
|
||||||
def legs_in_animal
|
def legs_in_animal
|
||||||
@@ -33,25 +33,25 @@ class AboutConstants < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_classes_inherit_constants_from_enclosing_classes
|
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
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
class Reptile < Animal
|
class Reptile < Animal
|
||||||
def legs_in_reptile
|
def legs_in_reptile
|
||||||
LEGS
|
LEGS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_subclasses_inherit_constants_from_parent_classes
|
def test_subclasses_inherit_constants_from_parent_classes
|
||||||
assert_equal __(4), Reptile.new.legs_in_reptile
|
assert_equal __(4), Reptile.new.legs_in_reptile
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
class MyAnimals
|
class MyAnimals
|
||||||
LEGS = 2
|
LEGS = 2
|
||||||
|
|
||||||
@@ -61,16 +61,16 @@ class AboutConstants < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_who_wins_with_both_nested_and_inherited_constants
|
def test_who_wins_with_both_nested_and_inherited_constants
|
||||||
assert_equal __(2), MyAnimals::Bird.new.legs_in_bird
|
assert_equal __(2), MyAnimals::Bird.new.legs_in_bird
|
||||||
end
|
end
|
||||||
|
|
||||||
# QUESTION: Which has precedence: The constant in the lexical scope,
|
# QUESTION: Which has precedence: The constant in the lexical scope,
|
||||||
# or the constant from the inheritance heirarachy?
|
# or the constant from the inheritance heirarachy?
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
class MyAnimals::Oyster < Animal
|
class MyAnimals::Oyster < Animal
|
||||||
def legs_in_oyster
|
def legs_in_oyster
|
||||||
LEGS
|
LEGS
|
||||||
@@ -83,5 +83,5 @@ class AboutConstants < EdgeCase::Koan
|
|||||||
|
|
||||||
# QUESTION: Now Which has precedence: The constant in the lexical
|
# QUESTION: Now Which has precedence: The constant in the lexical
|
||||||
# scope, or the constant from the inheritance heirarachy? Why is it
|
# scope, or the constant from the inheritance heirarachy? Why is it
|
||||||
# different?
|
# different than the previous answer?
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user