Forum: Ruby immutable and enumerable?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
508861510639b56d61eb30e6a28b01d9?d=identicon&s=25 John Maclean (Guest)
on 2006-02-12 14:13
(Received via mailing list)
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?
0b561a629b87f0bbf71b45ee5a48febb?d=identicon&s=25 Dave Burt (Guest)
on 2006-02-12 15:43
(Received via mailing list)
John Maclean 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

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
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 Robert Klemme (Guest)
on 2006-02-12 16:08
(Received via mailing list)
Dave Burt <dave@burt.id.au> 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
This topic is locked and can not be replied to.