독도 광고 모금 캠페인


'구구단'에 해당되는 글 1건

  1. 2008/04/07 구구단
2008/04/07 12:39

구구단


array의 each 메소드 이용

mul = (2...10).to_a
mul.each{|element| puts "2x"+element.to_s+"="+(2*element).to_s }


array의 each 메소드와 Proc 객체 활용

mul = (2...10).to_a
danproc = Proc.new{|element| mul.each{|m| puts element.to_s+"x"+m.to_s+"="+(element*m).to_s}}
danproc.call(2)


X.each do...end 활용

mul = (2...10).to_a
danproc = Proc.new{|element| mul.each{|m| puts element.to_s+"x"+m.to_s+"="+(element*m).to_s}}
(2...10).to_a.each do |danbase|
danproc.call(danbase)
end


또 다른 방법이 있으려나..?




Trackback 0 Comment 0