Method(Function) def hi(name) p "hi " + name end hi("666") # => "hi 666" hi "code" #括号省略 => "hi code" def hello name p "hello #{name}" end hello "world" # => "hello world" Method 参数 def hi name="code" p "hi " +name end hi # => "hi code" def hi name,age=32 p "#{name} is #{age}" end hi "code" # => "code is 32" hi "code", 54 # => "code is 54" Method 返回值 凡有方法都有返回值,方法体最后一行代码的返回值默认会做为方法的返回值,也可以显式的使用return关键字 def hi p "ok" end hi # =>nil……

Continue reading