다음 코드 예제에서 두 번째 (sheetplus) 메서드는 @name 및 @cupupation 인스턴스 변수를 선택하는 것처럼 보이지만 첫 번째 (sheet) 메서드는 nil을 반환하는 이유는 무엇입니까? 나는 치명적인 것을 놓치고있는 것처럼 느껴진다. 그러나 나는 기본적으로 세계 최악의 루비 프로그래머 다.클래스 메서드에서 한 메서드가 인스턴스 변수를 받아들이는 것처럼 보이고 다른 메서드가 그렇지 않은 이유는 무엇입니까?
class Test
def initialize(name, occupation)
@name = name
@occupation = occupation
def sheet
"This is #@name, who is a/an #@occupation"
def sheetplus
"This is #@name, who is a/an #@occupation, but why does this method succeed where the previous one fails?"
end
end
end
end
사용 "탭"키를 성공! –