博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ruby语法_Ruby函数(方法)语法
阅读量:2514 次
发布时间:2019-05-11

本文共 1199 字,大约阅读时间需要 3 分钟。

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”)

翻译自:

ruby语法

转载地址:http://gavwd.baihongyu.com/

你可能感兴趣的文章
Map的遍历
查看>>
hibernate中cache二级缓存问题
查看>>
My third day of OpenCV
查看>>
Java并发计数器探秘
查看>>
特色博客
查看>>
[Python] RuntimeError: Invalid DISPLAY variable
查看>>
Android的View和ViewGroup分析
查看>>
淘宝爆款详情页制作的几个方法(理论)
查看>>
c语言单链表实现
查看>>
php无限极分类
查看>>
08——别让常逃离析构函数
查看>>
echarts.js中的图表大小自适应
查看>>
Linux总结
查看>>
Delphi的FIFO实现
查看>>
swt combo 自动补全
查看>>
一个自动上传ip到ftp服务器的bat脚本
查看>>
Hive配置优化
查看>>
《C与指针》第十三章练习
查看>>
vue 各种 import 引入
查看>>
python基础学习笔记——Python基础教程(第2版 修订版)第18章)(程序打包)
查看>>