I'm new to ruby.
What I don't get is, if some patterns appear repetitively in my code, there should be something I could do to subtract that part and save the matter.
E.g., here is what it looks like now:
class Book
def initialize(title, author)
@title = title
@author = author
end
def info
puts [@title, @author]
end
end
What I want the code to look like:
class Book(title, author)
def info
puts [title, author]
end
end
What reasons I could come up with:
initialize gets called every time an object has been created. so if there's something I want to do every time an object is created, initialize is the official way.
the initialize indicates how many arguments a constructor would take. without which it would take 0.
But it still looks unnecessary to me. Is it possible that I could alter the syntax to look like the second one instead of having to do the initialization every time I create a Class, if I have nothing special to execute upon construction?