Reputation: 451
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!
Upvotes: 0
Views: 440
Reputation: 160191
You're trying to call it on an array, instead of passing it the array.
funny_sort w # Or with parens...
funny_sort(w)
You may have another issue with that new_array
and new_string
in there, though, and I suspect that .each
does not return what you believe it does.
Upvotes: 2