class Test
def initialize
@var = "125"
end
def testmethod
puts @var
puts "accessing me from child class"
end
end
class TestExtension < Test
def method1
puts @var = "One Hundred and twenty five"
testmethod()
end
end
t = Test.new
p = TestExtension.new
p.method1
t.testmethod
출력 :인스턴스 변수
One Hundred and twenty five
One Hundred and twenty five
accessing me from child class
125
accessing me from child class
내 질문입니다 TestExtension
클래스에서 선언되고 @var
의 값에 접근하는 대신 값을 액세스하는 자식 클래스에 TestExtension
결과를 testmethod()
에 접근하는 Test
클래스에 선언되었습니다. 맞습니까?
(영어 텍스트의 모든 식별자 주변의 모든 코드 라인과 역 따옴표 전에 4 공백을 넣어). 자세한 내용은 다음을 참조하십시오. http://stackoverflow.com/editing-help – Jakob