SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: OOP Ruby help

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OOP Ruby help

    hi, im have a code snippet here:

    Code:
    class Song
    	def initialize(name, artist, duration)
    		@name = name
    		@artist = artist
    		@duration = duration
    	end
    	
    	attr_reader :name, :artist, :duration
    end
    
    song = Song.new("Bicyclops", "Fleck", 260)
    song.artist
    song.name
    song.duration
    i use a text editor to save the .rb file and use the commandline of instantrails...when i execute the .rb file, it is blank..then i have to include the methode puts just to show the strings to be stored int the artist, name, and duration. in the book, it is written like the bove code, but when executed, it shows nothing, then like i said, i have to add the method puts to show the string..is this a problem?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I think your book is running that code in irb (an interactive ruby interpreter), which will display values in that manner. Puts is what you use if you're executing a script and want the output displayed somewhere.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •