Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build an Address Book in Ruby Class Design Address Class: Part 1

Sarah A. Morrigan
Sarah A. Morrigan
14,329 Points

Can address book data be held on a separate file and called from either address.rb or contact.rb?

So here, in address.rb the data is held

home = Address.new
home.kind = "Home"
home.street_1 = "123 SE Main St."
home.city = "Portland"
home.state = "OR"
home.postal_code = "97214"

while all other data (names, phone numbers) are held in contact.rb.

It seems to make a better sense to create a separate file to save all the data away from the codes. Is it even possible (without getting into all the complicated mySQL stuff)?

2 Answers

You could probably write the data to a file, and read the data in from that file.

Check out http://ruby.bastardsbook.com/chapters/io/ for more information.

rowend rowend
rowend rowend
2,926 Points

Yes, you can write an array/any other structure like dict in data.rb file. Then import your file and file your objects with this structure.