From: Jeremy Bopp Date: 2011-10-19T23:38:20+09:00 Subject: Re: Custom Method not running On 10/19/2011 01:44, Junayeed Ahnaf Nirjhor wrote: > Hello, > > > > Why this code is not running, anyone ? > > > > def dictionary_sort arr > > return arr if arr.length <=1 > > middle = arr.pop > > less = arr.select{|x| x.downcase < middle.downcase} > > more = arr.select{|x| x.downcase >= middle.downcase} > > sort(less) + [middle] + sort(more) > > end > > words = ['can','feel','singing.','like','A','can'] > > puts(dictionary_sort(words).join(' ')) > > > > Error is following: > > > > C:/Users/Nirjhor/RubymineProjects/dictionary sort.rb:20:in `dictionary_sort': undefined method `sort' for main:Object (NoMethodError) > > from C:/Users/Nirjhor/RubymineProjects/dictionary sort.rb:23:in `' > > from -e:1:in `load' > > from -e:1:in `
' Take a closer look at the error message. It's telling you that on line 20 of your source file that you're attempting to call a method named "sort" which has not been defined. Maybe there is another method which you have already defined for sorting arrays that you should use instead. Sorry to be coy about my answer. However, you appear to be writing your own sorting method despite the fact that Ruby already includes such a method for Array objects, so this smells like a homework problem to me. Good luck! :-) -Jeremy