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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:10:01+00:00 2026-05-28T05:10:01+00:00

This seems very strange to me but I have a script that I’m running

  • 0

This seems very strange to me but I have a script that I’m running that is somehow keeping previous values from previous loads of the script. The values in req1 aren’t being dumped on successive loads of the script.

Here’s the script:

require 'amazon_product'

req1 = nil 
req1 = AmazonProduct["us"]

puts req1.inspect

req1.configure do |c|
  c.key    = "[...]"
  c.secret = "[...]"
  c.tag    = "[...]"
end

puts req1.inspect

req1 << {
    'Version'                => '2010-11-01',
    'Operation'              => 'ItemLookup',
    'SearchIndex'            => "Books",
    'Keywords'    => 'Corrections'
    #, 'A' => 'B' 
}
puts req1.inspect

resp = req1.get

File.open( File.join(File.dirname(__FILE__), 
      "amazon_response.xml"), 'w') {|f| f.write(resp.body) }

Here are the steps:

  • open irb (via rails c)
  • run the script via the load command
  • uncomment the A=>B line
  • run script again
  • comment the A=>B line
  • run script again

At the end the req1 object will have 'A' => 'B' in it. I’m unclear on why this would be happening since it looks like I’m creating a new object on every run on of the script. It appears that the object is being remembered on every run.

What’s the best practice to prevent this sort of thing? I’ve tried a few things but feel like I’m grasping at straws since I don’t understand why it’s happening in the first place.

  • 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-28T05:10:02+00:00Added an answer on May 28, 2026 at 5:10 am

    You’re not restarting irb, so it depends on what AmazonProduct[] does. From its source:

    def self.[](locale)
      @requests[locale] ||= Request.new(locale)
    end
    

    It’s caching, creating a new request iff one doesn’t exist yet.

    From one standpoint, it’s “because it doesn’t have a new“. new is only called when the locale hasn’t been loaded yet. From another, it’s less new/not-new, but caching, without documenting it may do so.

    Given the behavior, it’s a reasonable assumption–and why my first thought was []‘s implementation.


    Regarding not restarting irb: if there isn’t a mechanism to reload the cache (I didn’t check), quickest thing to do would be to monkey-patch [] and always retrieve a new Request for a given locale.

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

Sidebar

Related Questions

I have a very strange memory leak problem, it seems that sqlite3_step is doing
I have got a very strange input issue in which it seems that my
This code compiles but looks very strange. I have a typical and simple parent/child
This seems very basic and I must be missing something, but here goes anyways...
I'm relatively new to the Python world, but this seems very straight forward. Google
This seems like it should be very simple but I can't get it to
This seems like it should be something very easy to do, but every time
It seems very basic, but I stuck on this one. $value = 0; foreach($this->products->result()
This is a very simple task in every language I have ever used, but
Strange Question i guess but i have this bit of code in my page...

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.