标签:ruby
class Person def initialize() puts "hello!" end # def initialize #()省略一样 # puts "hello!" # end #参数默认值 # def initialize (param = "1900lab") # 参数带有默认值 # puts "hello! " + param # end #可变长参数 def youInput(*names) puts "input #{names.join(",")}!" end end p = Person.new() 和 p = Person.new 一样,没有参数()可以省略。
class Person attr "name",true end p = Person.new() p.name = "xiao ming" puts p.name
标签:ruby
原文地址:http://blog.csdn.net/iitvip/article/details/30848601