日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ruby语法_Ruby函数(方法)语法

發布時間:2023/12/9 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ruby语法_Ruby函数(方法)语法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

ruby語法

The Ruby?language makes it easy to create functions.

Ruby語言使創建函數變得容易。

Function Syntax

功能語法

def functionname(variable)?? return <value>end

def functionname(variable)return <值>結束

Examples

例子

Your function can compute values and store them in local variables that are specific to the function. Those values can then be returned with the return statement.

您的函數可以計算值并將它們存儲在該函數特定的局部變量中。 然后可以使用return語句返回這些值。

def say_hello(name)?? var =?“Hello, ” + name?? return varend

def say_hello(name)var =“你好,” +名稱返回varend

The return statement also can be shortened for very simple functions into a single line

對于非常簡單的功能,還可以將return語句縮短為一行

def say_hello(name)?? return “Hello, ” + nameend

def say_hello(name)返回“ Hello,” + nameend

You can simplify the function further. The last expression that is evaluated is automatically returned by the method. For example:

您可以進一步簡化功能。 該方法自動返回最后一個求值表達式。 例如:

def say_hello(name)?? “Hello, ” + nameend

def say_hello(name)“你好,” + nameend

This would return the same value as the prior functions.

這將返回與先前功能相同的值。

To call a function

調用功能

function param1, param2

函數param1,param2

or

要么

function(param1,param2)

函數(param1,param2)

Example

puts say_hello(“Geek”)

放置say_hello(“ Geek”)

翻譯自: https://www.howtogeek.com/howto/programming/ruby/ruby-function-method-syntax/

ruby語法

總結

以上是生活随笔為你收集整理的ruby语法_Ruby函数(方法)语法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。