# Having trouble looping through an array of Regular Expressions in a Rake task

**URL:** <https://www.ruby-forum.com/t/having-trouble-looping-through-an-array-of-regular-expressions-in-a-rake-task/187131>\
**Category:** Rails\
**Created:** [April 17, 2010, 9:54pm UTC](https://www.ruby-forum.com/t/having-trouble-looping-through-an-array-of-regular-expressions-in-a-rake-task/187131 "2010-04-17T21:54:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![command0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9adbd/32.png) [@command0](https://www.ruby-forum.com/u/command0)\
**Post date:** [April 17, 2010, 9:54pm UTC](https://www.ruby-forum.com/t/having-trouble-looping-through-an-array-of-regular-expressions-in-a-rake-task/187131/1 "2010-04-17T21:54:49Z")

</div>

Hey guys, I was wondering if someone could give me some insight on an  
issue I’m having.

I am working on a Rails app that will be a data efficient, user  
friendly New King James Version of the Bible.

What I am presently doing is making a Rake task to build all the  
chapters to all of the books.

So I created an array of Regex’s, to insert the expression to look  
for, but when I loop through the array, I’m getting an error, and not  
sure why.

This is what I have:

desc “Build All Chapters”  
task :build\_all\_chapters =\> :environment do  
require ‘mechanize’  
agent = Mechanize.new  
agent.get(“[Version not found - Version Information - BibleGateway.com](http://www.biblegateway.com/versions/New-King-James-)  
Version-NKJV-Bible/#booklist”)  
books = Book.all.count  
i = 0  
book\_names = Array[/Genesis/, /Exodus/, /Leviticus/, /Numbers/, /  
Deuteronomy/, /Joshua/, /Judges/, /Ruth/,  
/1+Samuel/, /2+Samuel/, /1+Kings/, /2+Kings/, /1  
+Chronicles/, /2+Chronicles/,  
/Ezra/, /Nehemiah/, /Esther/, /Job/, /Psalm/, /  
Proverbs/, /Ecclesiastes/, /Song+of+Solomon/,  
/Isaiah/, /Jeremiah/, /Lamentations/, /Ezekiel/, /  
Daniel/, /  
Hosea/, /Joel/, /Amos/, /Obadiah/,  
/Jonah/, /Micah/, /Nahum/, /Habakkuk/, /Zephaniah/, /  
Haggai/, /Zechariah/, /Malachi/, /Matthew/,  
/Mark/, /Luke/, /John/, /Acts/, /Romans/, /1  
+Corinthians/, /2+Corinthians/, /Galatians/,  
/Ephesians/, /Philippians/, /Colossians/, /1  
+Thessalonians/, /2+Thessalonians/, /1+Timothy/,  
/2+Timothy/, /Titus/, /Philemon/, /Hebrews/, /  
search=James/, /1+Peter/, /2+Peter/, /1+John/,  
/2+John/, /3+John/, /Jude/, /Revelation/]  
books.times do  
book\_names.each do |book\_title|  
chapters = agent.page.links\_with(book\_title).count  
Chapter.create!(:name =\> “Chapter #{i += 1}”, :book\_id =\> i +=  
1)  
end  
end  
end

I get the error:

undefined method `all?’ for /Genesis/:Regexp

I’m not sure what this error means, and I haven’t had much luck on  
Google…

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![command0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9adbd/32.png) [@command0](https://www.ruby-forum.com/u/command0)\
**Post date:** [April 18, 2010, 11:30am UTC](https://www.ruby-forum.com/t/having-trouble-looping-through-an-array-of-regular-expressions-in-a-rake-task/187131/2 "2010-04-18T11:30:04Z")

</div>

On Apr 17, 8:53 pm, command0 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I get the error:
> 
> undefined method `all?’ for /Genesis/:Regexp
> 
> I’m not sure what this error means, and I haven’t had much luck on  
> Google…

Looks like you’re calling links\_with incorrectly - looks like  
links\_with is expecting a hash (eg :title =\> some\_regex, :href =\>  
some\_other\_regex ) rather than just a bare regular expression

Fred
