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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:18:07+00:00 2026-06-02T08:18:07+00:00

So basically what I am doing is creating a list of URLs that I

  • 0

So basically what I am doing is creating a list of URLs that I am parsing from a specific url…in this case, the base url is the local variable url.

What I want to do is, pass url to my_list – which works fine now…but once I have that list, I then want to pass the first element of the array list declared in the method my_list to the method add_category.

See the code:

def add_category(url)
    new_url = url + '/web'  
end

url = 'http://www.someurl.com'

def my_list(url)
    root = Nokogiri::HTML(open(url))
    list = root.css("a").map do |link|
        [link.text, link[:href]]           
      end

end

my_list(url)

add_category(list[0])

Where I am going is, I want to modify every single URL in the list array per the rules I specify in the add_category method.

Thoughts?

  • 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-02T08:18:10+00:00Added an answer on June 2, 2026 at 8:18 am

    You cannot refer to method’s local variables from outside. They are called “local” for a reason! 🙂

    It seems that your my_list method is simply generating a list that you want to use later. So, save its return value to a local variable (in the caller scope) and use however you want. Check this out:

    def add_category(url)
        url + '/web'  
    end
    
    url = 'http://www.someurl.com'
    
    def my_list(url)
        root = Nokogiri::HTML(open(url))
        root.css("a").map do |link|
            [link.text, link[:href]]           
        end
    end
    
    list = my_list(url)
    
    new_url = add_category(list[0][1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an iphone/ipad app that basically reads XML documents and creates tableviews from
This is my first time doing these things. Basically I am creating a batch
I am basically doing a tutorial but my program seems to have errors that
Why isn't my if-statement working? It doesn't accept NSCFStrings... Basically I'm doing this: if
Basically, I'm doing this: var phone = $(#phone).val(); Then I want to check if:
Basically, I am creating a dynamic 2d ArrayList. private ArrayList<char[]> myArray; This code below
I'm creating a map editor for a XNA game that I'm working on. Basically,
I am creating a webpage with javascript that is doing some processing and building
Basically I'm trying to open a URL in my .NET application. This can be
The way I know how to represent a linked list is basically creating a

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.