The following code
require 'yaml'
class MyObject
def initialize(value)
@value = value
end
def to_yaml()
@value + @value
end
end
puts [MyObject.new("a"), MyObject.new("b")]
Generated the following output on Ruby 2.1.3p242:
---
- !ruby/object:MyObject
value: a
- !ruby/object:MyObject
value: b
Where I expected it to be
---
- aa
- bb
As if I called to_yaml
on every object inside the Array:
puts [MyObject.new("a").to_yaml, MyObject.new("b").to_yaml]
What am I doing wrong?