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 trialNicholas Lee
12,474 PointsCreating Hashes, getting => nil
When jason adds a new value to the hash and then prints it looks like this.
ap h { "name" => "Jason" "hello" => "world" } => {"name"=>"Jason", "hello"=>"world"}
When I do it, I only get back, then a => nil
ap h { "bye" => "world", "name" => "Nick" } => nil
Is this an "ap" issue? When I was originally setting it up and typed in require 'rubygems' it returned false. Someone posted and said that only means you are already using it.
Why am I missing => {"name"=>"Jason", "hello"=>"world"} ? And what does that mean?
2 Answers
Dan Mirda
3,992 Points==Quote:
"When jason adds a new value to the hash and then prints it looks like this.
ap h { "name" => "Jason" "hello" => "world" } => {"name"=>"Jason", "hello"=>"world"}"
==EndQuote
I don't think that is what he did in the video. If you stop the video at 4:37 it appears he did the following:
$ h = { "name" => "Jason", "hello" => "world" }
=> { "name" => "Jason", "hello" => "world" }
$ ap h
{
"name" => "Jason",
"hello" => "world"
}
The assignment of the hash to h is on a seperate line of the call to ap where h is a parameter.
Rachel Klein
7,388 PointsI am having this same issue: whenever I try to create a hash, => nil is returned. I tried the solutions above (going through the "require" sequence again) and I am still getting the same results. Does anyone have any other ideas?
Eric Carey
6,820 PointsEric Carey
6,820 PointsNot sure if you're still on this, but the information you received was correct. Typing:
require 'rubygems'
Will return "=> false" from Ruby 1.9 and up because it's required by default. Basically if you require a gem in irb and you get "=> false" without an error message, then it's probably already loaded.
To solve this specific issue, try typing:
require 'awesome_print'
If you get "=> true", then try running the hash exercise again. Should work this time. If you get an error message, then it may not have installed properly.
Edit: I obviously couldn't read the markdown sheet.