Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Foundations Hashes Enumerable

JAKZ AIZZAT
JAKZ AIZZAT
7,813 Points

Is the output for Symbols as Hash Keys correct?

Is it the true answer?

require 'rubygems'
gem 'awesome_print'
require 'awesome_print'

h1 = Hash.new


h1['name'] = 'Jakz'
h1['age'] = 20
h1['email'] = 'woopixii@gmail.com'




def convert(h)
    h2 = Hash.new

    h.map { |key,value|  
        h2[key.to_sym] = value
    }

    ap h2


end

convert h1

Is it this the answer for Extra credit for Hashed Topic?

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I think the output is OK, but read the rest of the assignment: they want you to write a function (or rather a method, which is the next topic covered in this course), and it should work recursively. So you want it to take arguments and you want it to go through each of those arguments.

JAKZ AIZZAT
JAKZ AIZZAT
7,813 Points

Ok. My bad. I didn't understand the question. I will code it and post it the answer

JAKZ AIZZAT
JAKZ AIZZAT
7,813 Points

Is it the true answer?

require 'rubygems'
gem 'awesome_print'
require 'awesome_print'

h1 = Hash.new


h1['name'] = 'Jakz'
h1['age'] = 20
h1['email'] = 'woopixii@gmail.com'




def convert(h)
    h2 = Hash.new

    h.map { |key,value|  
        h2[key.to_sym] = value
    }

    ap h2


end

convert h1
Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

If it produces the results you expected then it's good.