C
Chris Pelow
Hi there,
I'm looking for help with my work here.I'm just learning Ruby.
Basically I have 5 names entered into an array. They have a firstname
and surname. A middlename is then optional.
What I want to do is to print out the names like this..
John Seymour Smith
Peter Jones
Mary Walsh
So it yields the middlename and prints it out if it has one.
Some of my code is as follows...
Attachments:
http://www.ruby-forum.com/attachment/4289/Person2.rb
I'm looking for help with my work here.I'm just learning Ruby.
Basically I have 5 names entered into an array. They have a firstname
and surname. A middlename is then optional.
What I want to do is to print out the names like this..
John Seymour Smith
Peter Jones
Mary Walsh
So it yields the middlename and prints it out if it has one.
Some of my code is as follows...
Code:
people << Person.new("John", "Paul", "Smith" )
people << Person.new("Mary","Barry", "Jones" )
people << Person.new("Chris","Townsend", "Barry" )
people << Person.new("Peter","", "Murphy" )
people << Person.new("Scott","", "Evans" )
people_sorted = people.sort
people_sorted.each do |person|
people_sorted.each_with_index do|person, index|
puts "Hi there #@index #@person!"
end
Attachments:
http://www.ruby-forum.com/attachment/4289/Person2.rb