# Newbie question about arrays

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-arrays/63716>\
**Category:** Ruby\
**Created:** [June 18, 2006, 1:11am UTC](https://www.ruby-forum.com/t/newbie-question-about-arrays/63716 "2006-06-18T01:11:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gautam\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Gautam\_D](https://www.ruby-forum.com/u/Gautam_D)\
**Post date:** [June 18, 2006, 1:11am UTC](https://www.ruby-forum.com/t/newbie-question-about-arrays/63716/1 "2006-06-18T01:11:23Z")

</div>

Hello all,

So I was going through the Ruby array documentation and came  
across Array. abbrev(pattern = nil). However, every time I run the  
example code in irb I get the following:

rb(main):001:0\> %w{ car cone }.abbrev  
NoMethodError: undefined method `abbrev’ for [“car”, “cone”]:Array  
from (irb):1  
irb(main):002:0\>

What am I doing wrong? Do I need to include a module? If so, how?

Thank you,  
Gautam

---

<div class="post-metadata">

**Author:** ![Gautam\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Gautam\_D](https://www.ruby-forum.com/u/Gautam_D)\
**Post date:** [June 18, 2006, 1:26am UTC](https://www.ruby-forum.com/t/newbie-question-about-arrays/63716/2 "2006-06-18T01:26:53Z")

</div>

On 6/18/06, Gautam D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):002:0\>
> 
> What am I doing wrong? Do I need to include a module? If so, how?

Nothing, the documentation is wrong, I used irb to check again

irb(main):007:0\> Array.new.methods.sort  
=\> [“&”, “\*”, “+”, “-”, “\<\<”, “\<=\>”, “==”, “===”, “=~”, “[]”, “[]=”,  
“ **id** ”, “ **send** ”, “all?”, “any?”, “assoc”, “at”, “class”, “clear”,  
“clone”, “collect”, “collect!”, “compact”, “compact!”, “concat”,  
“delete”,  
“delete\_at”, “delete\_if”, “detect”, “display”, “dup”, “each”,  
“each\_index”,  
“each\_with\_index”, “empty?”, “entries”, “eql?”, “equal?”, “extend”,  
“fetch”,  
“fill”, “find”, “find\_all”, “first”, “flatten”, “flatten!”, “freeze”,  
“frozen?”, “grep”, “hash”, “id”, “include?”, “index”, “indexes”,  
“indices”,  
“inject”, “insert”, “inspect”, “instance\_eval”, “instance\_of?”,  
“instance\_variable\_get”, “instance\_variable\_set”, “instance\_variables”,  
“is\_a?”, “join”, “kind\_of?”, “last”, “length”, “map”, “map!”, “max”,  
“member?”, “method”, “methods”, “min”, “nil?”, “nitems”, “object\_id”,  
“pack”, “partition”, “pop”, “private\_methods”, “protected\_methods”,  
“public\_methods”, “push”, “rassoc”, “reject”, “reject!”, “replace”,  
“respond\_to?”, “reverse”, “reverse!”, “reverse\_each”, “rindex”,  
“select”,  
“send”, “shift”, “singleton\_methods”, “size”, “slice”, “slice!”, “sort”,  
“sort!”, “sort\_by”, “taint”, “tainted?”, “to\_a”, “to\_ary”, “to\_s”,  
“transpose”, “type”, “uniq”, “uniq!”, “unshift”, “untaint”, “values\_at”,  
“zip”, “|”]  
irb(main):008:0\>

and there just is no abbrev method.

However you are right with the module idea, quite impressive for a  
newbie

require “abbrev”  
=\> true  
irb(main):002:0\> Array.new.methods.sort  
=\> [“&”, “\*”, “+”, “-”, “\<\<”, “\<=\>”, “==”, “===”, “=~”, “[]”, “[]=”,  
“ **id** ”, “ **send** ”, “abbrev”, “all?”, “any?”, “assoc”, “at”, “class”,  
“clear”, “clone”, “collect”, “collect!”, “compact”, “compact!”,  
“concat”,  
“delete”, “delete\_at”, “delete\_if”, “detect”, “display”, “dup”, “each”,  
“each\_index”, “each\_with\_index”, “empty?”, “entries”, “eql?”, “equal?”,  
“extend”, “fetch”, “fill”, “find”, “find\_all”, “first”, “flatten”,  
“flatten!”, “freeze”, “frozen?”, “grep”, “hash”, “id”, “include?”,  
“index”,  
“indexes”, “indices”, “inject”, “insert”, “inspect”, “instance\_eval”,  
“instance\_of?”, “instance\_variable\_get”, “instance\_variable\_set”,  
“instance\_variables”, “is\_a?”, “join”, “kind\_of?”, “last”, “length”,  
“map”,  
“map!”, “max”, “member?”, “method”, “methods”, “min”, “nil?”, “nitems”,  
“object\_id”, “pack”, “partition”, “pop”, “private\_methods”,  
“protected\_methods”, “public\_methods”, “push”, “rassoc”, “reject”,  
“reject!”, “replace”, “respond\_to?”, “reverse”, “reverse!”,  
“reverse\_each”,  
“rindex”, “select”, “send”, “shift”, “singleton\_methods”, “size”,  
“slice”,  
“slice!”, “sort”, “sort!”, “sort\_by”, “taint”, “tainted?”, “to\_a”,  
“to\_ary”,  
“to\_s”, “transpose”, “type”, “uniq”, “uniq!”, “unshift”, “untaint”,  
“values\_at”, “zip”, “|”]  
[“ala”, “ada”, “b”, “broad”, “crypt”].abbrev  
=\> {“ala”=\>“ala”, “al”=\>“ala”, “b”=\>“b”, “broa”=\>“broad”,  
“crypt”=\>“crypt”,  
“c”=\>“crypt”, “ad”=\>“ada”, “cr”=\>“crypt”, “br”=\>“broad”,  
“broad”=\>“broad”,  
“cryp”=\>“crypt”, “ada”=\>“ada”, “bro”=\>“broad”, “cry”=\>“crypt”}  
irb(main):004:0\>

And you are set for the Ruby Q., good luck 😉

Robert

> Thank you,  
> Gautam

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein

---

<div class="post-metadata">

**Author:** ![Gautam\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Gautam\_D](https://www.ruby-forum.com/u/Gautam_D)\
**Post date:** [June 18, 2006, 2:00am UTC](https://www.ruby-forum.com/t/newbie-question-about-arrays/63716/3 "2006-06-18T02:00:08Z")

</div>

On 6/18/06, Robin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> You need to require the abbrev module in order to use this functionality.  
> Would be nice to remove the abbrev entry in the core doc of Array, or  
> alternatively, indicate that this  
> is an extension of Array implemented in the abbrev file.  
> The doc is quite good, really, ty all for your work!  
> Robert

Thanks,

> Robin

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein

---

<div class="post-metadata">

**Author:** ![Gautam\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Gautam\_D](https://www.ruby-forum.com/u/Gautam_D)\
**Post date:** [June 18, 2006, 1:32am UTC](https://www.ruby-forum.com/t/newbie-question-about-arrays/63716/4 "2006-06-18T01:32:59Z")

</div>

Gautam D. wrote:

> What am I doing wrong? Do I need to include a module? If so, how?  
> Yes, you need to do require ‘abbrev’.

It should be mentioned in the documentation, but it is not. I think  
Gavin S. is the one to contact in this case, so this mail is CC to  
him.

Gavin, could you add a note to lib/abbrev.rb, something like:  
You need to require the abbrev module in order to use this  
functionality.

Thanks,  
Robin

---

<div class="post-metadata">

**Author:** ![Gautam\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Gautam\_D](https://www.ruby-forum.com/u/Gautam_D)\
**Post date:** [June 18, 2006, 4:51am UTC](https://www.ruby-forum.com/t/newbie-question-about-arrays/63716/5 "2006-06-18T04:51:48Z")

</div>

Robert,

Thank you for you quick response.

Gautam.
