ruby.new
ruby.new
输出:print、puts、p
注释
#say hello
=begin
this is a long comment
=end
变量
local: time or _time
instance: @time
class: @@time
global $time
数据类型
Numeric
String
Symbol
Boolean
Array
Hash
方法
def plus(x,y)
z = x + y
return z
end
plus(3,4)
def plus x,y
x + y
end
plus 3,4
- 只有overriding没有overloading
block
def hello
yield
end
hello {puts "hello, block"}
[1,2,3,4,5].each{|i| puts i}
[1,2,3,4,5].each_with_index{|i, index| puts i, index}
[1,2,3,4,5].map{|i| i**2 }
[1,2,3,4,5].select{|i| i%2==0 }
[1,2,3,4,5].reject{|i| i%2==0 }
[1,2,3,4,5].inject{|sum, i| sum += i}
lambda 和 Proc
class
class Bird
attr_accessor :name, :sex
attr_reader :age
attr_writer :hometown
def initialize name
@name = name
end
def self.fly
puts "bird can fly"
end
def say
puts "i am #{@name}"
end
end
bird = Bird.new("didi")
bird.sex = "male"
Bird.fly
class LittleBird < Bird
def initialize name
super(name)
end
end
module
- ruby 没有interface,但是有 module 与 mixin 机制。
module Eat
def eat
p "i can eat"
end
end
module Sleep
def sleep
p "i can sleep"
end
end
class Pig
include Eat
include Sleep
end
Pig.new.eat
Pig.new.sleep
module Math
PI = 3.14
end
Math::PI
code
ruby.new的更多相关文章
- 安装cocoapods遇到两大坑-Ruby版本升级和Podfile的配置
今天安装cocoapods #移除原有ruby源 $ gem sources --remove https://rubygems.org/ #使用可用的淘宝网 $ gem sources -a htt ...
- Unable to download data from http://ruby.taobao.org/ & don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
安装cocoapods,记录两个问题! 1.镜像已经替换成了 http://ruby.taobao.org/, 还是不能不能安装cocoapods, 报错:Unable to download dat ...
- 安装了ruby后怎么安装sass
在命令行中输入 ruby -v 查看版本号 先移除默认的https://rubygems.org源,命令为gem sources --remove https://rubygems.org/,按回车 ...
- ruby 基础知识(一)
突然今天发现一大神的博客:http://www.cnblogs.com/jackluo/archive/2013/01/22/2871655.html 相信初学者会受益颇多 ruby 参考文档 ...
- ruby 基础知识(二)
ruby 中的动态方法 http://singleant.iteye.com/blog/1680382 Rails 大量使用了符号(symbol).符号看上去很像变量名,不过以冒号作为前缀.符号的例 ...
- Ruby安装Scss
Ruby安装Scss 引言 已经许久不写HTML了,今天有点以前的东西要改.但是刚装的Windows10,已经没有以前的Web开发环境了.只好重新安装. 结果Webstorm装好后配置Scss出现错误 ...
- fzf by ruby
fzf by ruby */--> fzf by ruby 1 github地址 https://github.com/junegunn/fzf 2 简介 软件通过匿名管道和grep扩展了bas ...
- The Safe Navigation Operator (&.) in Ruby
The most interesting addition to Ruby 2.3.0 is the Safe Navigation Operator(&.). A similar opera ...
- Ruby on Rails 创建https应用
1. 创建证书请求文件条件:私钥+证书签名请求+opensslyum install -y opensslmkdir /root/ssl/ && cd /root/ssl/openss ...
- Ruby数组
Ruby数组是有序的,任何对象的整数索引的集合.每个数组中的元素相关联,并提取到的一个索引.下标与C或Java相似,从0开始.负数索引假设数组末尾,也就是说-1表示最后一个元素的数组索引,-2是数组中 ...
随机推荐
- Android向SDCard中上传文件时报错:Failed to push items
向sdcard中添加文件为什么总是提示Failed to push the item(s) Failed to push XXXXX.txt on emulator- : Read-only ...
- Jenkins修改域认证,非域用户忘记密码处理
一.认证域地址修改 1. 编辑配置文件 vi $JENKINS_HOME/jenkins/config.xml 2.修改如下内容: <securityRealm class="huds ...
- GetTextMetrics
该函数的参数要求是一个TEXTMETRIC结构体的指针 也就是说我们可以定义一个结构类型的变量 将该变量的地址传递进来 通过该函数就能得到当前字体的信息来填充这个结构体 int CXuexi2View ...
- C# 缩略图算法
代码写多了,有些使用过的方法和技巧会一时半会想不起来,平日记录下来,方便自己和有需要的人日后查阅. using (var stream = new FileStream(physicalPath, F ...
- 自定义ORM框架(转转)
ORM背景 在数据库界,主流的数据库都是关系型数据库,其采用的关系型数据结构模型,无论从数学上还是实践中都相当的成熟,得到非常广泛的应用.在关系型数据结构理 论中,所有的数据都组织成一个个相互独立的二 ...
- php中文匹配
PHP判断字符串中是否含有中文 <? $str = "测试中文"; echo $str; echo "<hr>"; //if (preg_ma ...
- try catch 学习记入
执行过程 public void method(Action action) { //2.method执行中 try { action(); //3.调用委托 "; //如果action执行 ...
- Oracle 判断 并 手动收集 统计信息 脚本
CREATE OR REPLACE PROCEDURE SchameB.PRC_GATHER_STATS AUTHID CURRENT_USER IS BEGIN SYS.DBMS_STATS.GAT ...
- Java中string拼接,StringBuilder,StringBuffer和+
Java中string拼接,StringBuilder,StringBuffer和+,到底哪个更合适? StringBuilder线程不安全,效率较线程安全的StringBuffer高.jdk1.5之 ...
- .OCX、.dll文件注册命令Regsvr32的使用
1.打开文件,打开需要注册的OCX文件或dll文件,2.然后根据需要进行OCX文件或DLL文件的注册和反注册 DLL.OCX注册方法--文件Regsvr32用法及情况介绍 使用过activex的人都知 ...