Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:51:31+00:00 2026-05-23T10:51:31+00:00

Yet another ruby question but this is a bunch of questions in one. I’m

  • 0

Yet another ruby question but this is a bunch of questions in one. I’m really starting to like rails but there are some questions that I’d just like to ask straight out.

Right now, I’m implementing a queue in sqlite. I already have a scaffold setup with this working OK. The purpose is for a web crawler to read through the array and determine which links he should crawl next.

The architecture in the program is 2 controllers. one for Job and one for crawler. The Jobs has the standard Crud interface supplied by scaffold. Where I’m falling down is I’m still trying to understand how these things communicate with eachother.

The Job is formatted as a url:string and depth:decimal. The table is already populated with about 4 objects.

@sitesToCrawl = Job.all

@sitesToCrawl.each {|x|puts Job.url}

I have a bunch of questions about the above.

At the moment, this was supposed to display all the jobs and I foolishly thought it would display plain text but its actually a hexidecimal pointer to the object itself. What Im trying to do is iterate through the @sitesToCrawl and put out each Jobs url.

Questions start here:

1: I know ruby is dynamically typed. Will @sitesToCrawl become an array like i want it to be with each slot containing a job.

2: @sitesToCrawl.each is pretty straighforward and I’m assuming its an iterator.
is X the name od the method or what is the purpose of the symbol or string between |*|

3: Puts and print are more or less the same yes? if i say @x = puts 3 then would x be 3?

4: Job.url. Can objects be referenced this way or should I be using

 #@sitesToCrawl = db.execute("SELECT url FROM jobs;")

where db is a new database

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:51:32+00:00Added an answer on May 23, 2026 at 10:51 am

    As Rubish Gupta pointed out, in your block, you should do x.url, otherwise you’re trying to access the url method on the class Job, not on instances of Job. In other words, in blocks, the items in the pipes are the arguments of the block, and each will iterate through your array, passing in one item at a time to your block. Check out the doc here.

    Just to extend this idea, each on Hashes (associative arrays, maps, whatever you know them as) will pass two variables to your block: a key and a value, like this:

    a_hash.each {|key_var, val_var| puts "#{key_var} is associated with #{val_var}"}
    

    Also, it’s been a bit since I’ve done plain ActiveRecord models, but you might look into doing

    @sitesToCrawl = Job.all.to_a
    

    since Job.all is a lazy finder in that it’s building a query in potentia: you’ve essentially built a query string saying SELECT * FROM jobs, but it might not be executed until you try to access the items. each might do that, I can’t remember off the top of my head, but if you’re using a debugger to look at it, I know you need to_a to get it to run the query.

    You should absolutely be using job_instance.url – that’s the beauty of ActiveRecord, it makes database access easy, provided everything gets set up right 🙂

    Finally, puts and print are almost the same – the difference is that puts "string" is essentialy print "sting"; STDOUT.flush – it flushes at the end of the statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess this question will sound familiar, but I am yet another programmer baffled
Yet another Scrabble project question... This is a simple one. It seems I am
This is related to another StackOverflow question from a year ago. But, a bit
This is yet another EXC_BAD_ACCESS question. Although I've done my homework and am certain
I'd really like to handle this without monkey-patching but I haven't been able to
Yet another Lucene.net question by an extreme newbie to it. This time, I have
So Yet another SMS question :-) I researched, but could not find a solution
I am trying to write a Ruby script in one file. I would like
yet another PHP question which I am stuck on, so here is what im
Yet another reason why I hate IE for being different. I've got this code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.