摘要: Everything is Object 一切皆对象a = "hello"a.class # => Stringb = 3.14b.class # => Floatc = %w[pear cat horse]c.class # => ArrayInstance Method & Instance Attribute 实例方法,实例属性Instance Method: 实例方法,成员方法,成员函数I... 阅读全文
posted @ 2018-02-17 21:00 罗道义 阅读(162) 评论(0) 推荐(0) 编辑
摘要: ## 代码规范1. 使用UTF-8编码2. 使用空格缩进,不使用tab, 1 tab = 2 spaces3. 不需要使用分号(;)和反斜杠(\)连接代码Demo```ruby# basic typesa = 1b = "hello world"# one linec = ["pear", "cat", "dog"]# or multiple linesc2 = [ "pear", "cat", ... 阅读全文
posted @ 2018-02-17 19:42 罗道义 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 变量赋值# 变量交换a = 1b = 2b,a = a,bputs aputs bputs '-' * 30x = [1, 2, 3]a, b = x #默认会把数组中的值依次赋值给 a ,bputs aputs bputs '-' * 30x = [1, 2, 3]a, *b = x #这里a会接受第一个元素 b用了*号 表示接受剩下所有的元素puts ap b#output21--------... 阅读全文
posted @ 2018-02-17 04:17 罗道义 阅读(200) 评论(0) 推荐(0) 编辑
摘要: Block 代码块Block是一个参数匿名参数Callback使用do/en或者{}来定义{puts 'hello'}Demo:# block usagedef hello puts 'hello method start' yield yield puts 'hello method end'endhello {puts 'i am in block'}#output h... 阅读全文
posted @ 2018-02-17 04:01 罗道义 阅读(142) 评论(0) 推荐(0) 编辑
本站总访问量