이 쿼리는 해시를 반환하므로 해시를 반복하고 테이블에 표시하면됩니다.
는 다음의 반복에 대한 간단한 예입니다 :
:
이
$ hashish = Hash.new
$ hashish = {'Sun, 30 Oct 2011'=>17, 'Wed, 02 Nov 2011'=>19, 'Fri, 11 Nov 2011'=>70, 'Sat, 12 Nov 2011'=>44, 'Sun, 13 Nov 2011'=>38, 'Sun, 20 Nov 2011'=>4, 'Mon, 21 Nov 2011'=>5, 'Sun, 27 Nov 2011'=>80, 'Sun, 04 Dec 2011'=>16, 'Sat, 31 Dec 2011'=>48, 'Mon, 02 Jan 2012'=>68, 'Tue, 03 Jan 2012'=>1, 'Wed, 04 Jan 2012'=>3, 'Sun, 08 Jan 2012'=>9, 'Mon, 09 Jan 2012'=>7, 'Wed, 11 Jan 2012'=>1, 'Thu, 12 Jan 2012'=>1}
$ hashish.each {|k,v| puts "Key is #{k} and value is #{v}"}
> Key is Sun, 30 Oct 2011 and value is 17
> Key is Wed, 02 Nov 2011 and value is 19
> Key is Fri, 11 Nov 2011 and value is 70
> Key is Sat, 12 Nov 2011 and value is 44
> Key is Sun, 13 Nov 2011 and value is 38
> Key is Sun, 20 Nov 2011 and value is 4
> Key is Mon, 21 Nov 2011 and value is 5
> Key is Sun, 27 Nov 2011 and value is 80
> Key is Sun, 04 Dec 2011 and value is 16
> Key is Sat, 31 Dec 2011 and value is 48
> Key is Mon, 02 Jan 2012 and value is 68
> Key is Tue, 03 Jan 2012 and value is 1
> Key is Wed, 04 Jan 2012 and value is 3
> Key is Sun, 08 Jan 2012 and value is 9
> Key is Mon, 09 Jan 2012 and value is 7
> Key is Wed, 11 Jan 2012 and value is 1
> Key is Thu, 12 Jan 2012 and value is 1
여기에 (당신이 ERB 또는 HAML를 지정하지 않았기 때문에 내가 HAML 코드를 사용하고 있습니다) 테이블에 표시하는 간단한 예제입니다
%table
%tr
- hashish.each do |k,v|
%td #{k}
%tr
- hashish.each do |k,v|
%td #{v}
또는
%table
- hashish.each do |k,v|
%tr
%td #{k}
%td #{v}
나에게 좋은 같은데, 감사 – simonmorley