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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:20:38+00:00 2026-05-16T06:20:38+00:00

I have a ‘strange’ problem, the following code converts the location lat value into

  • 0

I have a ‘strange’ problem, the following code converts the location lat value into a string (With a + sign for each iteration) leading to an eventual exception when comparing values. I’ve tried the code with values for another location and it works fine. The only difference is that the other numbers were negatives.

location= {:lng => 2.0781,:lat => 41.2899}
while location[:lat] < top
      sleep(1)
      checkTweets(location)
      bottom+=0.075
      location[:lat] = bottom
end

The issue occurs before entering the check tweets location. The values for the hash are as follows

To to conclude, my question is can anyone explain to me why location[:lat] ends up being a string in this circumstance?

Bottom is initialized as 30.0400 which is assigned to the :lat value. The checkTweets method simply writes a file based on a mongodb query.

Right I found the solution to this. It was the twitter library which was turning the Hash float values into strings.

Am I wrong in assuming that the scope of the variable in the checkTweets method should not impact the location variable here, they are both declared in seperate methods, they are not class level.

  • 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-16T06:20:39+00:00Added an answer on May 16, 2026 at 6:20 am

    I wrong in assuming that the scope of the variable in the checkTweets method should not impact the location variable here, they are both declared in seperate methods, they are not class level.

    No, but variable scope is not the issue here. The location variable is local to your method and as such cannot be changed by the checkTweets method. That is correct.

    However the object that is referenced by the location variable can be changed from the checkTweets method and that is exactly what happens (though I have to say that mutating arguments is very bad style).

    A little example to illustrate reference semantics and mutation in ruby:

    def f1(arr)
      arr = [1,2,3] # Changes the variable arr, which is local to f1
                    # This change is not visible on the outside
    end
    
    def f2(arr)
      arr.concat [1,2,3] # Changes the object that arr refers to
                         # This change will be visible any place where the same
                         # array is referenced
    end
    
    foo = [42,23]
    f1(foo)
    # foo is still [42, 23]
    f2(foo)
    # foo is now [42, 23, 1, 2, 3]
    

    Here the variable foo hasn’t been changed to refer to another object (that would not be possible from inside a method), but the object that foo refers to has been changed. The same happens in your checkTweets method.

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

Sidebar

Related Questions

Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have a look at the following code to find X^y. /* Find exponent in
Have a xml string, goal is to replace an xml element value to a
Have the following code. The height is variable so the height of the floating
Have whats probably a simple problem with using parent in if and each statements
Have a look at the following code. The goal here is to return a
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
have a nice day. I got problem when trying to create an image from
Have been following Rails Tutorial by Michael Hart rails version 3.0 on mac OS
Have some code: using (var ctx = new testDataContext()) { var options = new

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.