0
어떻게 표시 할 수 있습니까? 헤더 %를 사용하여 서식을 지정합니까? 나는 수업 방법에서 아무것도하지 않습니다하지만, 인스턴스 메소드% 문자열 형식이 클래스 메소드에서 작동하지 않습니까? (루비)
class Stats
attr_accessor :type, :count;
def initialize type
@type = type
@count = 0
end
def self.display
"%s %4s " % ["header1",'header2']
#puts 'headers'
ObjectSpace.each_object(Stats) { |o|
puts o
}
end
def to_s
"%-9s %4d " % [@type, @count]
end
end
videos = Stats.new 'Videos'
videos.count = 3
article = Stats.new 'Article'
webinars = Stats.new 'Webinars'
Stats.display
@Phil 로스 : 얼굴이 빨의 이모티콘은 무엇입니까? :-) 고맙습니다 – Radek