Class: KargWare::Song

Inherits:
Object
  • Object
show all
Defined in:
lib/Song.rb

Overview

A class Song for music

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, artist, duration) ⇒ Song

attr_reader :name, :artist



10
11
12
13
14
# File 'lib/Song.rb', line 10

def initialize(name, artist, duration)
  @name     = name
  @artist   = artist
  @duration = duration
end

Instance Attribute Details

#artistObject (readonly)

Returns the value of attribute artist.



6
7
8
# File 'lib/Song.rb', line 6

def artist
  @artist
end

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/Song.rb', line 6

def duration
  @duration
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/Song.rb', line 6

def name
  @name
end

Instance Method Details

#echoObject



21
22
23
# File 'lib/Song.rb', line 21

def echo
  puts to_s
end

#to_sObject



16
17
18
19
# File 'lib/Song.rb', line 16

def to_s
  # format('%s (%s) [ %s ]', @name, @artist, @duration)
  "#{@name} (#{@artist}) [ #{@duration} ]"
end