# Counting words for visual details

**URL:** <https://www.ruby-forum.com/t/counting-words-for-visual-details/176245>\
**Category:** Ruby\
**Created:** [September 27, 2009, 10:42pm UTC](https://www.ruby-forum.com/t/counting-words-for-visual-details/176245 "2009-09-27T22:42:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 27, 2009, 10:42pm UTC](https://www.ruby-forum.com/t/counting-words-for-visual-details/176245/1 "2009-09-27T22:42:24Z")

</div>

I’ve made a survey in Rails where I want people to pick three words,  
characteristics, from a list of 30 words for 20 different visual  
details; linear, organic, symmetry, etc.

I save each answer for each user, with the visual detail in one column  
and the three words in an array in a single varchar column. E.g. for  
Linear a user doing the survey might pick Word1,Word2,Word3.

What would be the best way to count the words picked for let’s say  
Linear? And also, count the ones most frequent.

( Not sure it’s best to ask here or in Rails forum but I suspect it  
could be here with some array or hash trick.)

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 28, 2009, 1:30am UTC](https://www.ruby-forum.com/t/counting-words-for-visual-details/176245/2 "2009-09-28T01:30:44Z")

</div>

> I save each answer for each user, with the visual detail in one column  
> and the three words in an array in a single varchar column. E.g. for  
> Linear a user doing the survey might pick Word1,Word2,Word3.
> 
> What would be the best way to count the words picked for let’s say  
> Linear? And also, count the ones most frequent.
> 
> ( Not sure it’s best to ask here or in Rails forum but I suspect it  
> could be here with some array or hash trick.)

Well, if you can create the query for the word array, then you can  
simply use the size() method to count the objects in the array:

word\_array = [‘Word1’, ‘Word2’, ‘Word3’] #query here instead  
word\_array.size # =\> 3

---

<div class="post-metadata">

**Author:** ![paulbutcher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a5b964/32.png) [@paulbutcher](https://www.ruby-forum.com/u/paulbutcher)\
**Post date:** [September 28, 2009, 7:22am UTC](https://www.ruby-forum.com/t/counting-words-for-visual-details/176245/3 "2009-09-28T07:22:12Z")

</div>

Ehsanul H. wrote:

> word\_array = [‘Word1’, ‘Word2’, ‘Word3’] #query here instead  
> word\_array.size # =\> 3

Thanks. I forgot to say that I want to count the occurrence of each of  
the 30 words. E.g. how many Word1 have they selected for Linearity? How  
many Word1 have they selected for Symmetry? And so on.
