# Immutable and enumerable?

**URL:** <https://www.ruby-forum.com/t/immutable-and-enumerable/66112>\
**Category:** Ruby\
**Created:** [February 12, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/immutable-and-enumerable/66112 "2006-02-12T14:13:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 12, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/immutable-and-enumerable/66112/1 "2006-02-12T14:13:15Z")

</div>

Every language and profession has it’s own language. Ruby is no  
exception. Can someone explain to me what the two terms above mean and  
why they are so crucial to Ruby?

Are they methods/classes ( don’t think so) /modules/some other thing?

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 12, 2006, 3:43pm UTC](https://www.ruby-forum.com/t/immutable-and-enumerable/66112/2 "2006-02-12T15:43:43Z")

</div>

John M. asked:

> Every language and profession has it’s own language. Ruby is no  
> exception. Can someone explain to me what the two terms above mean and  
> why they are so crucial to Ruby?
> 
> Are they methods/classes ( don’t think so) /modules/some other thing?

Immutable is not a Ruby-specific term. Its meaning in this group is  
pretty  
much its dictionary definition, that is, “not subject to change.” We  
(and  
other OO programmers) apply it to objects that don’t have “mutator”  
methods,  
methods that change the object itself.

Say you have an object, and offer it to a function of some kind, then  
check  
its value afterwards. If the object is immutable (like a Fixnum in Ruby)  
your variable is guaranteed to be the same as before. Otherwise, that  
function may have altered the object.

The method Object#freeze lets you make any object immutable.

Enumerable (in Ruby) is a module, included by Array and Hash. For  
documentation:  
[http://www.ruby-doc.org/core/classes/Enumerable.html](http://www.ruby-doc.org/core/classes/Enumerable.html)

From that page:  
" The Enumerable mixin provides collection classes with several  
traversal  
and searching methods, and with the ability to sort. The class must  
provide  
a method each, which yields successive members of the collection. If  
Enumerable#max, min, or sort is used, the objects in the collection must  
also implement a meaningful \<=\> operator, as these methods rely on an  
ordering between members of the collection."

Cheers,  
Dave

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 12, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/immutable-and-enumerable/66112/3 "2006-02-12T16:08:31Z")

</div>

Dave B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> these methods rely on an ordering between members of the collection."  
> The term “enumerable” is also often used to denote classes that include  
> this  
> module and implement an each method as in “String is enumerable.”

Kind regards

```
robert

```
