# What is that?

**URL:** <https://www.ruby-forum.com/t/what-is-that/114188>\
**Category:** Rails\
**Created:** [September 9, 2007, 12:52pm UTC](https://www.ruby-forum.com/t/what-is-that/114188 "2007-09-09T12:52:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexey.Creopolis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@alexey.Creopolis](https://www.ruby-forum.com/u/alexey.Creopolis)\
**Post date:** [September 9, 2007, 12:52pm UTC](https://www.ruby-forum.com/t/what-is-that/114188/1 "2007-09-09T12:52:51Z")

</div>

Does anyone can define this function ?

- range.inject(Hash.new(0)){|h,e| h[e] += 1; h} \*

range is array of integers like: [1,22,12,8,45,3,etc…]

🙂

---

<div class="post-metadata">

**Author:** ![alexey.Creopolis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@alexey.Creopolis](https://www.ruby-forum.com/u/alexey.Creopolis)\
**Post date:** [September 9, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/what-is-that/114188/2 "2007-09-09T13:17:54Z")

</div>

alexey.Creopolis wrote:

> Does anyone can define this function ?
> 
> - range.inject(Hash.new(0)){|h,e| h[e] += 1; h} \*
> 
> range is array of integers like: [1,22,12,8,45,3,etc…]

It’s a counter, it will return a hash with the entries in range as keys  
and the number of occurences of each entry as values. So if range is [1,  
1, 2, 3] it will return { 1 =\> 2, 2 =\> 1, 3 =\> 1 }

Is this what you wanted to know?

–  
Cheers,

- Jacob A.

---

<div class="post-metadata">

**Author:** ![alexey.Creopolis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@alexey.Creopolis](https://www.ruby-forum.com/u/alexey.Creopolis)\
**Post date:** [September 11, 2007, 1:40pm UTC](https://www.ruby-forum.com/t/what-is-that/114188/3 "2007-09-11T13:40:28Z")

</div>

right 🙂
