From: Mark Sargent Date: 2006-10-19T07:24:49+09:00 Subject: Re: Displaying Hash Problems ------=_Part_65124_24927697.1161210285380 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/18/06, Morton Goldberg wrote: > > Also consider: > > #create new song array > aName = Hash.new ### This clobbers the previous value of aName > aName['Title'] = newSong.get_song_title > aName['Type'] = newSong.get_song_type > aName['Artist'] = newSong.get_song_artist > > p aName Thanx for that. I've corrected that, but the below code still won't work correctly, CODE OUTPUT: mark@marklaptop:~/study/ruby$ ruby songs.rb Enter your name Mark Enter song type Rock Enter song title Wire Enter song artist U2 ["Name", "Title", "Artist", "Type", "aName", "newSong.get_song_title", " newSong.get_song_artist", "newSong.get_song_type"] I wish to dislay like this, Name value Title value Artist value Type value Cheers. Mark Sargent. CODE: ##define song class class Songs def set_song_type(type) @song_type = type end def set_song_title(title) @song_title = title end def set_song_artist(artist) @song_artist = artist end def get_song_title return @song_title end def get_song_type return @song_type end def get_song_artist return @song_artist end end ##create user name for array name puts "Enter your name" aName = gets() ##create new song from class, Songs newSong = Songs.new puts "Enter song type" newSong.set_song_type(gets()) puts "Enter song title" newSong.set_song_title(gets()) puts "Enter song artist" newSong.set_song_artist(gets()) #create new song array songList = Hash.new songList['Name'] = 'aName' songList['Title'] = 'newSong.get_song_title' songList['Type'] = 'newSong.get_song_type' songList['Artist'] = 'newSong.get_song_artist' ##display array contant puts p(songList.keys+songList.values) -- "Tell me and I'll forget, show me and I may not remember, involve me, and I'll understand." Native American Proverb ------=_Part_65124_24927697.1161210285380--