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是数组中 ...
随机推荐
- [欢度国庆]为什么我们今天还要学习和使用C++?(转载)
在各种新的开发语言层出不穷的今天,在Java和C#大行其道今天,我们为什么还要学习和使用C++?现在学习C++将来有用吗?学习C++要花费那么多时间和精力,这一切都值得吗?现在学习C++有钱途吗? 这 ...
- TComboBox组件的重要属性
TComboBox组件的重要属性 CharCase--------此属性用于设置编辑框内文字的大小写DropDownCount---此属性用于设置当用户下拉组合框时不需要加滚动条就能显示的项的个数Dr ...
- Android中通过Java获取Webview加载内容
有时候我们需要在加载webview时,获取加载完成的内容,当然,WebView也是有可能包含javascript.通过以下操作,我们是可以获取到WebView加载的内容. 1.自定义一个内部类,获取W ...
- 学习笔记之AJAX无刷新分页
利用AJAX实现无刷新分页技术原理: 其主要是利用AJAX的异步处理机制,实现数据的异步传递,它隐藏了客户端向服务端请求数据的状态,在客户端表现为无刷新的显示状态. 实现分页的步骤: 1.客服端点击页 ...
- Django新手图文教程
Django新手图文教程 本文面向:有python基础,刚接触web框架的初学者. 环境:windows7 python3.5.1 pycharm专业版 Django 1.10版 pip3 一 ...
- MVC 中集成 AngularJS1
在 ASP.NET MVC 中集成 AngularJS(1) 介绍 当涉及到计算机软件的开发时,我想运用所有的最新技术.例如,前端使用最新的 JavaScript 技术,服务器端使用最新的基于 R ...
- [JS]_proto_和prototype到底有啥区别
是时候拿出我珍藏多年的这张图了: 首先,要明确几个点: 1.在JS里,万物皆对象.方法(Function)是对象,方法的原型(Function.prototype)是对象.因此,它们都会具有对象共有的 ...
- Android中的自动朗读(TTS)
Android的自动朗读支持主要是通过TextToSpeech来完成,该类提供了如下一个构造器TextToSpeech(Context context,TextToSpeech.OnInitListe ...
- delphi 程序窗体及控件自适应分辨率(通过ComponentCount遍历改变字体大小以及上下左右)
unit untFixForm; interface uses Classes, SysUtils, Controls, Forms; type TFontedControl = class(TCon ...
- Xamarin devexpress datagrid 样式
DevExpress的提供光与暗的内置,可以应用到主题GridControl改变其外观. 主题 iOS版 Android版 光(默认适用于iOS) 黑暗(默认为Android) 应用预定义的主题 ...