0
0

More than 3 years have passed since last update.

Ruby学習#30 Initialize Method

Posted at

class Book
attr_accessor :title, :author, :pages
def initialize(title, author, pages)
@title = title
@author = author
@pages = pages
end
end

book1 = Book.new("Harry Potter","JK Rowling",400)
book2 = Book.new("Lord of the rings","Tolkein",500)

puts book1.author

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0