# Limit attributes written out by to\_yaml

**URL:** <https://www.ruby-forum.com/t/limit-attributes-written-out-by-to-yaml/52167>\
**Category:** Rails\
**Created:** [January 11, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/limit-attributes-written-out-by-to-yaml/52167 "2006-01-11T17:47:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Williak\_FISK](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ee59a6/32.png) [@Williak\_FISK](https://www.ruby-forum.com/u/Williak_FISK)\
**Post date:** [January 11, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/limit-attributes-written-out-by-to-yaml/52167/1 "2006-01-11T17:47:17Z")

</div>

I want to write out a series of records to a text file so that I can  
quickly edit them and then upload then again into the database. To do  
this I am using YAML and some code that looks like this:

item = Item.find 153  
File.open( ‘item.yaml’, ‘w’ ) do |out|  
YAML.dump( item, out )  
end

This dumps out all the field names and values which are stored in the  
attributes hash. The output looks something like this:

- !ruby/object:Item  
attributes:  
image\_height: ‘’  
maximum\_value: ‘’  
minimum\_value: ‘’  
item\_id: 153  
default\_value: ‘’  
… many more fields

However I don’t want all these fields. How can I limit the YAML output  
to just include the fields that I want?

I know that I can override to\_yaml\_properties to specify the fields that  
i want from a class. But that really only lets me choose whether I want  
to export @attributes or not. I think that I could override  
to\_yaml\_properties of @attributes. Something like this

class Item  
class \<\<@attributes  
def to\_yaml\_properties  
# …?  
end  
end  
end

But I’m not too sure what I should write there?  
Or maybe I should be overriding def removed\_email\_address@domain.invalid\_yaml ?

Does anyone have any ideas?

Thanks

```
  image_alignment: ''
  display_format: Vertical
  minimum_number_responses:
  item_sub_text: ''

  page_number: 5
  row_text_width:
  email_address_yn: N
  survey_id: 153
  other_yn: N
  random_answer_order_yn: N
  database_dsn: ''
  image_width: ''
  other_display_type:
  subitem_count:
  answer_total:
  item_text: "<span style=\"font-weight:bold\">When a good has 

```

positive network externalities,  
this means that when using the product:"  
order\_number: 26  
item\_alias: ‘’  
image\_path: ‘’  
maximum\_number\_responses:  
maximum\_length:  
item\_type\_id: 3  
database\_sql: ‘’  
other\_text: “Other, please specify”  
required\_yn: N

However there
