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

  • Home
  • SEARCH
  • 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 8669419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:28:12+00:00 2026-06-12T18:28:12+00:00

I have a List class implemented with a Node class. My #remove! method is

  • 0

I have a List class implemented with a Node class. My #remove! method is as follows:

def remove!(list_item)
  find list_item do |i|
    if i == nil
      return
    else
      i.pointer = i.pointer.pointer
    end
  end
end

#find does as I expect, returning the node previous to the one containing the datum searched for. So I expect this to set the previous item’s pointer to the object after the searched-for item, which should remove the current item from the list.

I think this has to do with how block scoping, and that i passed to the block is not directly referencing the object it should while in the block, and thus cannot overwrite the value of its pointer. How can I force this block to alter this value, without explicitly declaring the value beforehand (which defeats the purpose of this block).

The #find method and the ‘#traverse’ method behave as expected, so I figure this block has to be to blame. I am trying to avoid either making the same function call twice, or declaring a throw-away variable, because I’ve taken an interest in functional programming and would like to try it out.

Edit per request:

The full code on github

The #find method

def find(item_to_find, current_item = @sentinel.pointer, previous_item = @sentinel)
  if current_item == @sentinel then puts "not found"; return nil end
  if current_item.datum == item_to_find
    return previous_item
  else
    find item_to_find, current_item.pointer, current_item
  end
end
  • 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-12T18:28:13+00:00Added an answer on June 12, 2026 at 6:28 pm

    Your find method never calls the block, it doesn’t store it anywhere, it doesn’t pass it along to another method, it doesn’t do anything at all with the block. It just ignores it. Therefore, your remove! method is really just

    def remove!(list_item)
      find list_item
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a tree structure as follows public class Node implements Comparable<Node> { private List<Node>
I have a class that implements a linked list. The class has a find()
i neeed something like this in C#.. have list in class but decide what
I have List of particular class. I want to save this List at a
I have a list of class object that I created as a variable in
I have a list of class items List<MyClass> I have a seperate object that
I have a list of ProjectItem class instances: List<ProjectItem> allProjects . I need to
I have a list of this class: public class Data { public string name
Let's say I have a list in a class which will be used in
I have the following function defined inside my linked list class. The declaration in

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.