Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Foundations Hashes Working With Hashes

Bruce McMinn
Bruce McMinn
10,029 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,029 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"}.