Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created May 25, 2009 23:53
Show Gist options
  • Save jarsen/117813 to your computer and use it in GitHub Desktop.
Save jarsen/117813 to your computer and use it in GitHub Desktop.
just something I cooked up real quick to show Art ruby's expressive power after he had done this same project in C++
#!/usr/bin/env ruby -wKU
class Contact
attr_accessor :name, :address, :city, :state, :zip_code, :phone
def initialize( name, address, city, state, zip_code, phone )
@name, @address, @city, @state, @zip_code @phone = name, address, city, state, zip_code, phone
end
def to_s
foo = "Name: #{name}\n"
foo << "Address: #{address}\n"
foo << "City: #{city}\n"
foo << "State: #{state}\n"
foo << "Zip Code: #{zip_code}\n"
foo << "Phone: #{phone}\n"
end
end
puts "Welcome to Contact Book"
print "Enter your name: "
name = gets.strip
print "Enter your address: "
address = gets.strip
print "Enter your city: "
city = gets.strip
print "Enter your state: "
state = gets.strip
print "Enter your zip_code: "
zip_code = gets.strip
print "Enter your phone: "
phone = gets.strip
contact = Contact.new name, address, city, state, zip_code, phone
puts "\nContact: \n#{contact.to_s}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment