Ruby主要方法
| 方法定义 | |||
| def hello(name) ... end |
|||
| 函数名 | 参数 | 作用 | 备注 |
| print(),puts(),p() | 任意 | 输出 | puts()带换行,p()不分析内容,带换行 插值 #{} |
| # =begin ....=end |
注释 | 单行 # 多行 =begin ....=end |
|
| 类相关 | |||
| class-name.include?() | 是否包含某模块 | ||
| ancestors() | 所有祖先 | ||
| superclass() | 直接的母类 | ||
| 运算符相关 | |||
| str.inspect() | 返回带格式的字符串 "\"str"\" 相当于Swift的String description |
||
| 控制语句 | |||
| if a > 5 (then) ... else ... end |
if | then可省略 | |
| while a > 5 (do) ... end |
while | do可省略 | |
| array.each do |var| ... end |
|||
| "sada".each_char { |chr| ... } |
|||
| 数据类型 | |||
| [a,b,c,d] | 数组 | ||
| {1: a, 2: b, 3: c} | hash | hash量和:之间不要有空格 myHash = {:a => 1, :b => 2, :c => 3}等价 访问用myHash[:a] |
|
| /abcd/ | 正规表现 | 最后加i(/abcd/i) 不区分大小写 | |
| 型变换 | |||
| .to_i | |||
| .to_s | |||
| .to_f | |||
| 命令行 | |||
| ARGV[] | 文件名后第一个为 ARGV[0] | ||
| 文件操作 | |||
| File.open | |||
| File.read | File.read("path")读取全部 | ||
| File.close | |||
| 常数 | 以大写字母开头 | ||
| 变数 | 以小写字母开头 | 本地变量 a 全局变量 $a 实例变量 @a 类变量 @@a |
|
| a, b, *c = 1, 2, 3,4,5,6,7 | a = 1, b = 2 c = [3, 4, 5, 6, 7] |
||
Ruby主要方法的更多相关文章
- 雷林鹏分享:Ruby CGI方法
Ruby CGI方法 以下为CGI类的方法列表: 序号方法描述 1CGI::new([ level="query"]) 创建 CGI 对象.query可以是以下值: query: ...
- Ruby数组方法整理
数组方法整理 方法列表: all().any().none()和one():测试数组中的所有或部分元素是否满足给定条件.条件可以是语句块中决定,也可以是参数决定 append():等价于push() ...
- Ruby中方法的设计理念
Ruby中的方法命名遵从与局部变量相同的规则和约定.这是一种设计理念:方法并不因其自身作为方法而被人关注,而是简单地作为提供值的表达式融入到程序的结构中.
- Day04 -玩弄Ruby的方法:instance method与class method
前情提要在第三天时,我们解说了如何在class里用include与extend,去使用module的method. Include is for adding methods to an instan ...
- ruby安装方法
安装 Ruby Ruby官网下载:http://www.ruby-lang.org/en/downloads/(官网下载链接) 安装过程中,得注意,勾选上添加到环境变量 安装完成后,查看是否安装成功 ...
- Ruby 离奇方法
send https://ref.xaio.jp/ruby/classes/object/send find https://ref.xaio.jp/ruby/classes/enumerable/f ...
- ruby发送邮件方法
#encoding:utf-8require 'mail'def send_email sum,fail,case_path,name,receive smtp = { :address => ...
- ruby select 方法,可用于先查询结果后,再次用条件限制
1. 用于条件过滤 @works=DworkPro.all.order(:work_type) @work_pro=@works.select{ |x| x.job_type == 7} 2. sel ...
- ruby中的可调用对象--方法
上一篇讲了ruby中的可调用对象proc和lambda,他们都是块转换成的对象.ruby中的可调用对象还有方法.通过使用method方法,并且以方法名作为参数(字符串或者符号),就可以得到一个方法对象 ...
随机推荐
- BubbleGum96 开箱杂谈与软件资源
前言 原创文章,转载引用务必注明链接. 拿到有一段时间了,一直在想写哪些内容.96boards发布以来,吸引了很多眼球.这里我就慢慢随便聊聊,希望能让大家对96boards有更多了解. 开箱 [开箱图 ...
- react 实现pure render的时候,bind(this)隐患
react 实现pure render的时候,bind(this)隐患 export default class Parent extends Component { ... render() { c ...
- go test test & benchmark
开发程序其中很重要的一点是测试,我们如何保证代码的质量,如何保证每个函数是可运行,运行结果是正确的,又如何保证写出来的代码性能是好的,我们知道单元测试的重点在于发现程序设计或实现的逻辑错误,使问题及早 ...
- com.sun.jdi.InvocationException occurred invoking method 异常
参考链接:https://stackoverflow.com/questions/4123628/com-sun-jdi-invocationexception-occurred-invoking-m ...
- 高速查询hive数据仓库表中的总条数
Author: kwu 高速查询hive数据仓库中的条数.在查询hive表的条数,通常使用count(*).可是数据量大的时候,mr跑count(*)往往须要几分钟的时间. 1.传统方式获得总条数例如 ...
- HTML5与Javascript 实现网页弹球游戏
终于效果图: 1. 使用html 5 的canvas 技术和javascript实现弹球游戏 总体流程图: 1.1 html5 canvas技术的使用 首先在html页面中定义画布. <canv ...
- IconTabPageIndicator
https://github.com/msdx/IconTabPageIndicator
- v-bind指令
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Raspberry Pi For Windows
Raspberry Pi ------For Windows Step 1: In order to write the image for SD,we should download and ins ...
- SpringMVC中返回JSON时乱码的解决方案
springMVC中返回JSON会出现乱码,解决如下: produces = "text/html;charset=UTF-8" @ResponseBody @RequestMap ...