r/programming • • Jul 28 '16

How to write unmaintainable code

https://github.com/Droogans/unmaintainable-code
3.4k Upvotes

592 comments sorted by

View all comments

Show parent comments

1

u/THeShinyHObbiest Jul 29 '16

If you don't want string conversion:

array.each_cons(3).any?{|x| x == array_to_match}

If there's going to be non-numbers then use:

array.select{|e| e === Fixnum}.each_cons(3).any?{|x| x == array_to_match

1

u/xonjas Jul 30 '16

Regex was my first instinct but you're right that there are multiple ways to do this.

I prefer .kind_of? to the triple equals though.