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 Working With Hashes

Bruce McMinn
Bruce McMinn
10,030 Points

=> nil vs. => "hash&key"

When I create a hash and return it using awesome_print, at the end I get a hash rocket and the 'nil' value.

2.0.0-p481 :006 > h = {"hello" => "world"} => {"hello"=>"world"} 2.0.0-p481 :007 > ap h { "hello" => "world" } => nil

When Jason creates a hash and returns it using awesome_print, at the end he gets a hash rocket and the hash repeated.

1.9.3-p125 :005> h = {"hello" => "world"} => {"hello"=>"world"} 1.9.3-p125 :006> ap h { "hello"=>"world" } => {"hello"=>"world"}

Any ideas on why mine is different?

1 Answer

Ace Motanya
Ace Motanya
31,756 Points

you only need to put ap h and that will return your hash.

Bruce McMinn
Bruce McMinn
10,030 Points

I edited my original post to show how Jason's is different.

So you see, it's not really about putting "ap h", it's why at the end I have =>nil

and Jason has =>{"hello"=>"world"}.