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 8150011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:57:55+00:00 2026-06-06T14:57:55+00:00

My problem is around the fact that I cannot pass by reference in Ruby.

  • 0

My problem is around the fact that I cannot pass by reference in Ruby.
I have two functions searching and get_title_ids.

I have two arrays in searching

(1) title (2) href
which needs to be updated.

def searching
    title = []
    href = []
    (0..20).step(10) do |i|
        prev= title.length
        title, href = get_title_ids(i, title, href) ## <<-- Should have just done "get_title_ids(i, title, href)"
        ## something which on next iteration will increase the ids and hrefs
        puts "\nthe title lenght is #{title.length} and href length is #{href.length}\n"
        assert_operator prev,:<,title.length,"After scrolling to bottom no new jobs are getting added" 
    end
end

def get_title_ids (start_from=0, title=[], href=[])
    #Part of code which can store all links and titles of jobs displayed
    (start_from..(titles.length-1)).each do |i|
            unless titles[i].text.chomp
                title << titles[i].text.chomp
                href << titles[i].attribute("href")
            end     
        end
    end
    return [title, href] ### <<---- this is what messed it up
end

The problem is I am unable to push new elements into the arrays title and href that have been defined in searching.

Each time I call get_title_ids i do not want to gather data that I had previously gathered(hence the start_form).

My problem is not memory but time. So i am not too concerned about the data being duplicated when I call the get_title_ids function as compared to the fact that I have to waste time scrapping data that I already scrapped in the previous for loop.

So does any one know how to hack the pass by reference in Ruby.

EDIT

SO from reading the questions below turns out I dint need to perform the return from get_title_ids. And then it all worked.

  • 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-06-06T14:57:56+00:00Added an answer on June 6, 2026 at 2:57 pm

    Arrays in ruby are most certainly passed by reference (well, technically, they are passed by value, but that value is a pointer to the array). Observe:

    def push_new ary
      ary << 'new element'
    end
    
    a = ['first element']
    push_new a
    a # => ["first element", "new element"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I spent around two hours on that problem, and I have visited these stackoverflow
I've done a lot of searching on SO and google around this problem, but
I have a work around for this problem, but I've been noticing some peculiar
I have problem with text drawing around Circle. I found great sample in C#
I have a problem when downloading a large file (around 400mb) with a web
I want to work around the fact that my WCF servicelayer can not handle
SOLVED: As it turns out, my problem was rooted in the fact that I
I have been searching around for ages trying to find a solution to my
Alright, this is a weird problem I'm having. I have two pages, which are
I've been batting this problem around in my head for a few days now

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.