views:

32

answers:

1

Hey, I am trying to convert this object to an array of ints e.g. array(3,4,6)

- - !ruby/object:Code 
attributes: 
  candidate_id: "3"
attributes_cache: {}

- !ruby/object:Code 
attributes: 
  candidate_id: "4"
attributes_cache: {}

- !ruby/object:Code 
attributes: 
  candidate_id: "6"
attributes_cache: {}

here is what I tried

result = @intersection.map{|c| c.candidate_id}

Thanks

+1  A: 

Try the following:

  • c[:candidate_id]

OR

  • c[:attributes][:candidate_id]

I'm not familiar with YAML, however you might want to try making hashes instead of Code objects. Additionally, if you do use a code class, you should ensure that you have and attr_accessor (and then your old code should work).

Maz
I get a - undefined method `attributes' for [#<Code >, #<Code >, #<Code >]:Array
Alex
using c[:candidate_id] with a attr_accesser I get a type error (Symbol as array index)
Alex
you do c.candidate_id with attr_accessor
Maz