From: Gautam Dey Date: 2006-06-18T11:48:33+09:00 Subject: Re: Newbie question about arrays. Robert, Thank you for you quick response. Gautam. On Jun 17, 2006, at 4:24 PM, Robert Dober wrote: > On 6/18/06, Gautam Dey wrote: >> >> 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? > > > 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 Quiz, 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