I'm learning ruby, and noticed that I cannot create a class method called puts
:
class Printer
def initialize(text="")
@text = text
end
def puts
puts @text
end
end
The error is:
`puts': wrong number of arguments (given 1, expected 0)
My expectation was that I could use the code like this:
p = Printer.new("hello")
p.puts
It's not just because puts
is a built-in method, though. For instance, this code also gives a syntax error:
def my_puts(text)
puts text
end
class Printer
def initialize(text="")
@text = text
end
def my_puts
my_puts @name
end
end