Newbie question about arrays

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

On 6/18/06, Gautam D. [email protected] 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 :wink:

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

On 6/18/06, Robin S. [email protected] 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

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

Robert,

Thank you for you quick response.

Gautam.