How do I access properties in an array of objects in Ruby? -


how use ruby access properties of object containing array of objects?

i have variable looks this:

@myvar = [#<myobject::mobject0x00000000000000="000", @id="1000",  @status="open", @color="red">, #<myobject::mobject0x00000000000001="001",  @id="1001", @status="closed", @blue="450">] 

i tried:

@myvar.each(|name| puts "status: #{name.status}  color: #{name.color}" 

but returns full object instead of property values.

when call array#each block, returns array itself. perhaps you're looking array#map:

array_of_strings = @myvar.map { |name| "status: #{name.status}  color: #{name.color}" } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -