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?
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?
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
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
Dave B. [email protected] 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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs