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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:14:39+00:00 2026-05-17T06:14:39+00:00

How to pass range in hash to iterate from index 1 to last? h

  • 0

How to pass range in hash to iterate from index 1 to last?

h = {}

h[1..-1].each_pair do |key,value|
  puts "#{key} = #{value}
end

This code returning error. how may i pass range in hash ??

EDIT:

I want to print first key and value without any calculations.

From second key and value i want to do some calculation on my hash.

For that i have written this code …
store_content_in_hash containing key and values.

first_key_value = store_content_in_hash.shift
f.puts first_key_value[1]
f.puts
store_content_in_hash.each_pair do |key,value|
  store_content_in_hash[key].sort.each {|v| f.puts v }
  f.puts
end

Any better way to solve out this problem ??

  • 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-17T06:14:40+00:00Added an answer on May 17, 2026 at 6:14 am

    In Ruby 1.9 only:

    Given a hash:

    h = { :a => :b, :c => :d, :e => :f }
    

    Go Like this:

    Hash[Array(h)[1..-1]].each_pair do |key, value|
        # ...
    end
    

    This will iterate through the following hash { :c => :d, :e => f } as the first key/value pair is excluded by the range.

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

Sidebar

Related Questions

Consider this Python snippet: for a in range(10): if a == 7: pass if
I want to pass a range (1d at this point) into my function, and
This question comes from a range of other questions that all deal with essentially
I'm using Boost.Range to pass around some data and a container class for this
there are lot`s of articles in the web, how to pass excel range in
I want to pass an ImageIcon instance by value as we know that by
How can I pass a parameter from batch to vbscript? My batch script sends
I'm using glDatePicker to generate a date range selection system. You have a From
I've got a highly complex class : class C: pass And I've got this
Here is my ugly little code snippet now: for i in range(5): try: self.startTime=time.time()

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.