Aaron
Aaron

Reputation: 4480

Variable from hash printing out surrounded with brackets and quotes

The first line of code prints the string correctly. However the same variable in the second line of code is surrounded with [""]. Why is that and how do I get rid of the surrounding quotes and brackets? temp_hash[0][:item] is from an array that holds hashes

 puts temp_hash[0][:item]
 puts "Sku is #{a} the amount sold is #{b} the name of the book is #{temp_hash[0][:item]} and the revenue per book is #{revenue.round(2)} "

Upvotes: 0

Views: 179

Answers (1)

Leah Zorychta
Leah Zorychta

Reputation: 13419

When you have an array in ruby: arr = ["1"] and do puts arr then the output will just be 1. what type is puts temp_hash[0][:item]? It sounds like it's an array, try this:

puts "Sku is #{a} the amount sold is #{b} the name of the book is #{temp_hash[0][:item].first} and the revenue per book is #{revenue.round(2)} "

Upvotes: 1

Related Questions