From: Robert Dober Date: 2006-06-18T08:24:44+09:00 Subject: Re: Newbie question about arrays. ------=_Part_27573_32331842.1150586681317 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 6/18/06, Gautam Dey wrote: > > Hello all, > > So I was going through the Ruby array documentation and came > across Array. abbrev(pattern =3D 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? Nothing, the documentation is wrong, I used irb to check again irb(main):007:0> Array.new.methods.sort =3D> ["&", "*", "+", "-", "<<", "<=3D>", "=3D=3D", "=3D=3D=3D", "=3D~", "[]= ", "[]=3D", "__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" =3D> true irb(main):002:0> Array.new.methods.sort =3D> ["&", "*", "+", "-", "<<", "<=3D>", "=3D=3D", "=3D=3D=3D", "=3D~", "[]= ", "[]=3D", "__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 =3D> {"ala"=3D>"ala", "al"=3D>"ala", "b"=3D>"b", "broa"=3D>"broad", "crypt"= =3D>"crypt", "c"=3D>"crypt", "ad"=3D>"ada", "cr"=3D>"crypt", "br"=3D>"broad", "broad"=3D= >"broad", "cryp"=3D>"crypt", "ada"=3D>"ada", "bro"=3D>"broad", "cry"=3D>"crypt"} irb(main):004:0> And you are set for the Ruby Quiz, good luck ;) Robert > Thank you, > Gautam > > > --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_27573_32331842.1150586681317--