I’m VERY new to Ruby, so please forgive me.
I created a method funny_sort that sorts an array naturally and then returns the new array,
def funny_sort(the_array)
the_array = new_array.each {|s| s.gsub /\D/, ""}
the_array = new_string.each{|s| s.to_i}
the_array = new_string.sort_by{|s| s.gsub /\D/, ""}
return the_array
end
w = ['app100le', 'car10rot', 'banana']
puts w.funny_sort
but when I run the program in Command prompt with Ruby and Rails, I get the following error:
sort.rb:10in '<main>': private method 'funny_sort' called for ["app1001e", "carrot10", "banana"]:Array <NoMethodError>
What am I doing wrong?
Thanks!
You’re trying to call it on an array, instead of passing it the array.
You may have another issue with that
new_arrayandnew_stringin there, though, and I suspect that.eachdoes not return what you believe it does.