Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

Ruby constructors

class Library
  attr_accessor :title, :author

  def initialize (title, author)
    @title = title
    @author = author
  end

  def readBook()
    puts "Reading #{self.title} by #{self.author}"
  end
end

book1 = Library.new("Shreds of tenderness","Dr Mwaniki")
puts book1.readBook()
puts book1.title
 
PREVIOUS NEXT
Tagged: #Ruby #constructors
ADD COMMENT
Topic
Name
8+2 =