Hi,
The key / value pairs can be iterated like this:
str = ''
contacts.each do |key, value|
str += key.to_s + ' : ' + value + ', '
end
puts 'contacts output : ' + str
There are more compact ways to do this but will not be as easy to see what
is happening.
Kind Regards,
Doug
On Sunday, June 7, 2015 at 8:31:44 AM UTC+1, Anonymity wrote:
>
> Hi Everyone,
>
> Here is the code I currently have:
>
> contacts = Hash.new
>
> x = 0
> y = 0
>
> if x <= 5
> puts "What contact would you like to add?"
> ui = gets.chomp
> contacts.store(y, ui)
> puts "Contact added is #{contacts}"
> x += 1
> y += 1
> puts "X is #{x}, Y is #{y}" # so I know if the values are being
> incremented
> else
> puts "You've reached the maximum # of contacts."
> end
>
> Also, how can I print a hash to the console without a key value?
>
> Thank you
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/fc3b27d4-4357-44bb-846b-a521f0139c6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.