Hash Parsing with Ruby -


i have array of hash shown below:

@line_statuses = [   {:name=>"1", :status=>"online"},   {:name=>"2", :status=>"online"} ] 

i'd parse each hash inside of @line_statuses array can print out name , status shown below.

1: online 2: online 

how go doing this?

technically @line_statuses variable array, have array of hashes. in ruby, iterate on array use .each method. then, in each iteration, can access values of hash using defined keys:

@line_statuses.each |hash|   puts hash[:name]   puts hash[:status] end 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -