Ruby检验变量
检验是否定义 | defined? (sample)
|
||||||||||||||||||||||||||||
检验是否有值 | sample.nil? | ||||||||||||||||||||||||||||
检验是否为空 | sample.empty? 只对数组和哈希表可用 |
||||||||||||||||||||||||||||
rails可用 empty? + nil? |
sample.blank? | ||||||||||||||||||||||||||||
rails可用 blank?的否定 是否有值(+数组哈希表是否空) |
|
||||||||||||||||||||||||||||
获取所属的类 |
instance.class 输出的是类,如Test等 |
||||||||||||||||||||||||||||
判断类 |
instance_of?(Object) arr = Array.new(4, 1) # [1, 1, 1, 1] |
||||||||||||||||||||||||||||
判断类2 better | is_a?, kind_of? (Object) 和instance_of?的区别 instance_of?只能判断自己当前的类 is_a?, kind_of?可以判断当前实例继承的类以及被包含的module |
||||||||||||||||||||||||||||
检验是否包含目标 | temp = [1, 2, 3] temp.include?(1) 不能用来比较哈希值 |
||||||||||||||||||||||||||||
是否给了代码块 | block_given? | ||||||||||||||||||||||||||||
检验是否有layout | content_for?(:sample) ? yield(:sample) : yield |
||||||||||||||||||||||||||||
检验是否冻结 |
frozen? |
||||||||||||||||||||||||||||
检验是否是指定的实例 |
equal? eql? |
||||||||||||||||||||||||||||
1.1")
1.2")
1.3")
1.4")
1.5")
%d\n", i)
member of %d\n", i)
of #{i}")
item.inspect);puts();
of #{item}")
----------------------------------------
1.1
----------------------------------------
asa[1, 2]
defined?: local-variable
nil?: false
empty?: false
----------------------------------------
1.2
----------------------------------------
check.rb:19: warning: class variable access from
toplevel
local: local-variable
Const: constant
$global: global-variable
@instance: instance-variable
check.rb:24: warning: class variable access from
toplevel
@@class: class variable
----------------------------------------
1.3
----------------------------------------
isArray: true
class: Array
----------------------------------------
1.4
----------------------------------------
Test
false
false
true
----------------------------------------
1.5
----------------------------------------
array test:
[1, 2, 3, 5]
temp include 1
temp include 2
temp include 3
temp has no member of 4
------------
hash test:
temp has no member of x
temp include :b
temp include :c
temp include :d
Ruby检验变量的更多相关文章
- 雷林鹏分享:Ruby 环境变量
Ruby 环境变量 Ruby 解释器使用下列环境变量来控制它的行为.ENV 对象包含了所有当前设置的环境变量列表. 变量描述 DLN_LIBRARY_PATH动态加载模块搜索的路径. HOME当没有参 ...
- Ruby 环境变量
Ruby 环境变量 Ruby 解释器使用下列环境变量来控制它的行为.ENV 对象包含了所有当前设置的环境变量列表. 变量 描述 DLN_LIBRARY_PATH 动态加载模块搜索的路径. HOME 当 ...
- centos7 Ruby环境变量配置
ruby安装参考博客:https://blog.csdn.net/yelllowcong/article/details/78362370 (Redis之集群redis-trib.rb环境的搭建-y ...
- JavaScript 检验变量
创建: 2019/02/20 迁入: 删除[WIP]标签(因为随时更新, 不存在完成不完成) 从[JavaScript 式与运算符]迁入typeof 更新: 2019/03/25 补充静态变量与参 ...
- Swift4 检验变量
创建: 2018/05/03 判断类 public func isKind(of aClass: Swift.AnyClass) -> Bool 是否是aClass或其子类的实例 publ ...
- ruby中实例变量、类变量等等的区别和联系
ruby的变量有局部变量,全局变量,实例变量,类变量,常量. 1.局部变量 局部变量以一个小写字母开头或下划线开头 局部变量有局部作用域限制(比如一个block内),它的作用域起始于声明处,结束于该声 ...
- [置顶] ruby变量详解(收集+整理)
ruby的变量有局部变量,全局变量,实例变量,类变量,常量. 1.局部变量 局部变量以一个小写字母开头或下划线开头 局部变量有局部作用域限制(比如一个block内),它的作用域起始于声明处,结束于该声 ...
- 雷林鹏分享:Ruby 变量
Ruby 变量 变量是持有可被任何程序使用的任何数据的存储位置. Ruby 支持五种类型的变量.您已经在前面的章节中大概了解了这些变量,本章节将为您详细讲解这五种类型的变量. Ruby 全局变量 全局 ...
- 理解Ruby中的作用域
作用域对于Ruby以及其它编程语言都是一个需要理解的至关重要的基础知识.在我刚开始学习ruby的时候遇到很多诸如变量未定义.变量没有正确赋值之类的问题,归根结底是因为自己对于ruby作用域的了解不够, ...
随机推荐
- UVA 140 Bandwidth (dfs 剪枝 映射)
题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...
- SSM java.lang.NullPointerException
如上图所示的异常 原来是少了这个东西,加上就好了
- MT6753 使用nt35596s 由于液晶极化出现的闪屏问题解决思路
咨询屏厂那边FAE , 若是液晶极化相关的问题,下面三种场景下比较容易复现现象,请协助在目前的故障机上做压力测试: 1.反复开关机(1000次), 2.按power键休眠和唤醒(1000次), 3.反 ...
- [cf360 div1.C]The Values You Can Make[Dp]
题意:有n个硬币,面值不同,求能组成K的方案中,每个方案的硬币可以凑成那些答案. 例如, K=5 面值={1,1,1,2,3} K={1,1,1,2} K={1,1,3} K={2,3} 那么答案是 ...
- [网络流24题] 骑士共存(cogs 746)
骑士共存问题«问题描述:在一个n*n个方格的国际象棋棋盘上,马(骑士)可以攻击的棋盘方格如图所示.棋盘 上某些方格设置了障碍,骑士不得进入. «编程任务:对于给定的n*n个方格的国际象棋棋盘和障碍标志 ...
- android开发里跳过的坑——android studio升级完成后eclipse adt无法正常使用
最近有时间,把android studio做了一次升级,升级完成后,悲催的发现eclipse不能正常运行了,网上查了好多资料,试了很多方法都不行,最后把eclipse使用的sdk与AS使用的SDK区分 ...
- 【Tomcat】tomcat logs 目录下各日志文件的含义
tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份.可以帮助我们更好的找出错误. 一. 认识各种目录的作用及记录的信息 目录
- Thinkphp5.0 的使用模型Model更新数据
Thinkphp5.0 的使用模型Model更新数据 (1)使用update()方法进行更新数据 一.where条件写在更新数据中 (这种情况更新的数据,必须含主键) $res = User::upd ...
- 创建Django项目(五)——URL配置和视图
2013-08-07 20:02:10| 1.新建blog的URL文件 在blog目录下新建文件"urls.py" : # -*- coding: ...
- ASPNET Core 部署 Linux — 使用 Jexus Web Server
第一步 安装.Net Core环境 安装 dotnet 环境参见官方网站 https://www.microsoft.com/net/core. 选择对应的系统版本进行安装.安装完成过后 输入命令查看 ...