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方法,并且以方法名作为参数(字符串或者符号),就可以得到一个方法对象 ...
随机推荐
- [NPM] Set default values for package.json using npm set
Npm by default uses global values when initializing a new package.json file. Learn how to set your o ...
- linux find 命令查找 复制
find 查找 find . -mtime -2 -a -path './.git*' -prune , -path './Cache' -prune -a -exec cp {} one \; rm ...
- React 组件开发注意事项
0.state的设定原则,如果render里用不到,则就不应该是一个state. 1.数组遍历时,用每一条数据的唯一标识作为key,尽量不要使用遍历的索引值作为key,如果它们从不重新排序,它们工作也 ...
- HDOJ 1217 Arbitrage(拟最短路,floyd算法)
Arbitrage Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- VirtualBox中使用双网卡实现CentOS既能上网(校园网)也能使用SSHclient
近期在虚拟机中使用linux操作系统,之前使用NAT方式上网,能够畅通无阻.可是使用SSHclient连接linux虚拟机就必须为其指定固定的IP地址.依照网上的配置方法使用桥接方式,这种方式是能够的 ...
- 解压Zip
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import ja ...
- appium-java-api
AppiumDriver getAppStrings() 默认系统语言对应的Strings.xml文件内的数据. driver.getAppStrings(String language) 查找某一个 ...
- 2016/05/25 PHP mysql_insert_id() 函数 返回上一步 INSERT 操作产生的 ID
定义和用法 mysql_insert_id() 函数返回上一步 INSERT 操作产生的 ID. 如果上一查询没有产生 AUTO_INCREMENT 的 ID,则 mysql_insert_id() ...
- Codeforces Round #422 (Div. 2) E. Liar 后缀数组+RMQ+DP
E. Liar The first semester ended. You know, after the end of the first semester the holidays beg ...
- webservice client setTimeOut
一:eclipse生成的client,基于axis client_sub.getOptions().setTimeOutInMilliSeconds(1000*60); client_sub表示一个客 ...