Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method `filter' for array

So I am trying to solve a class problem/homework on repl.it, in ruby, and this is the error listing I'm given.

ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]

undefined method `filter' for [{:r=>1, :c=>0}, {:r=>0, :c=>1}]:Array
(repl):61:in `escape'
(repl):79:in `maze_escape'
(repl):82:in `<main>'

I can't understand the reason for this, because filter is clearly a method that is defined for the class Array, as a part of Ruby core, Here

like image 270
kchak Avatar asked Dec 05 '22 09:12

kchak


1 Answers

You are using ruby version 2.5.5.

Array#filter was added to ruby version 2.6.0.

However, the method is merely an alias for Array#select - so you can use this instead, if you are unable to upgrade the ruby version right now.

Note: The documentation you linked to is for ruby version 2.6.3 (i.e. the latest, at the time of writing). You can see the (almost-identical) documentation for version 2.5.5 here.

like image 89
Tom Lord Avatar answered Dec 14 '22 23:12

Tom Lord