要注意参数,可变长度参数,和参数默认值
还有对象的特殊方法
class Person
def say1(word1,word2)
puts word1+word2
end
# variable var
def say2(*word)
puts word
end
# default var
def say3(word = "something")
puts word
end
end
tom = Person.new
tom.say1("hello","world")
tom.say2("hello","world","too")
tom.say3
tom.say3 "else"
# special method
def tom.specialMethod
puts "special method"
end
tom.specialMethod
输出
helloworld
hello
world
too
something
else
special method