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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:27:55+00:00 2026-05-25T03:27:55+00:00

This is a very basic question but I’m having a bit of trouble understanding

  • 0

This is a very basic question but I’m having a bit of trouble understanding Rubys hash sort method.

Basically whats happening is I’m receiving a cannot convert string to integer so my first guess is I’m sorting the array by a string (which is actually a number). The array contains hashes and I’m trying to sort it by one of the hashes values that I’ve identified with a key.

Heres how I’m sorting my array:

@receivedArray =(params[:respElementDatas])

    puts @receivedArray.class #Its definitely an array
    @sortedArray = @receivedArray.sort_by{|ed| ed["element_type_id"]}

The error I’m getting is can’t convert String into Integer on the sort line.

Naturally I assumed that

Just a quick question.
Am i right in saying that ‘ed’ is an object that is stored in the array and I’m referencing it correctly? Also any pointers on how to fix it?

  • 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-25T03:27:56+00:00Added an answer on May 25, 2026 at 3:27 am

    Your @receivedArray is an array of arrays or has at least one array in it. For example:

    a = [[1,2,3],[4,5,6]]
    [[1, 2, 3], [4, 5, 6]]
    a.sort_by { |e| e['x'] }
    # TypeError: can't convert String into Integer
    
    a = [{:a => :a},{:b => :b},[1,2,3]]
    [{:a=>:a}, {:b=>:b}, [1, 2, 3]]
    a.sort_by { |e| e['x'] }
    # TypeError: can't convert String into Integer
    
    a = [{'where' => 'is'},{'pancakes' => 'house'}]
    [{"where"=>"is"}, {"pancakes"=>"house"}]
    a.sort_by { |e| e['x'] }
    # No error this time
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this maybe a very basic question but I'm having a bit of
This might be a very basic question, but I am a bit confused about
This may look a very basic question but I am having a problem accessing
I know, this might be a very basic question but I am not 100%
This is very basic question from programming point of view but as I am
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
Apologies if this is a very basic question, but I am preparing to create
I realise that this is a very basic question, but it is one which
Ok, I know this is a very basic question, but my head is swimming
This should be a very basic design question, but for some reason it doesn't

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.