[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Displaying Hash Problems

Morton Goldberg

10/18/2006 4:44:00 AM

On Oct 17, 2006, at 11:58 PM, Mark Sargent wrote:

> Hi All,
>
> just getting back into learning Ruby and thought I'd play with
> classes and
> hashes today. Below code produces the following ouput,
>
>
> mark@marklaptop:~/study/ruby$ ruby songs.rb
> Enter your name
> Mark
> Enter song type
> Rock
> Enter song title
> I Was Made For Loving You
> Enter song artist
> Kiss
>
> TitlenewSong.get_song_titleArtistnewSong.get_song_artistTypenewSong.ge
> t_song_type
>
>
> CODE:
>
> mark@marklaptop:~/study/ruby$ cat songs.rb
> ##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
> aName = Hash.new
> aName['Title'] = 'newSong.get_song_title'
> aName['Type'] = 'newSong.get_song_type'
> aName['Artist'] = 'newSong.get_song_artist'
>
> ##display array contant
> puts
> puts(aName)
>
>
> --
>
> I'm figuring it has something to do with how I assigned the values
> to the
> keys, but, cannot for the life of me see what. Any suggestions for
> me for
> where to look? Cheers.

puts does funny things to arrays. try p instead.

p aName

Regards, Morton



1 Answer

Morton Goldberg

10/18/2006 4:57:00 AM

0

On Oct 18, 2006, at 12:43 AM, Morton Goldberg wrote:

> puts does funny things to arrays. try p instead.
>
> p aName

Oops, that should be: puts does funny things to arrays and hashes.

Regards, Morton