竹林品雨

业精于勤荒于嬉,行成于思毁于随

10. RubyMonk Primer 习题知识点汇总

####1.计算数组中某个元素出现的次数 [9,3,4,9,5].count(9) #2 ####2. 随机数rand rand(9) #返回小于9的(0到8)随机整数 ####3. 检测某个元素是否包含与数组include? [9,3,4,9,5].include?(9) #true [9,3,4,9,5].include?(7) #fa...

9. I/O tips 记录

###9. I/O introduction ####9.1 Streams ####9.2 Using the File Class 文件读取 mode = "r+" file = File.open("xxx",mode) 文件的读取模式mode有如下可选 Mode | Meaning -----+---------------------------------------...

8. module intro

###8. module intro ####8.1 Getting Modular module only hold behaviour,unlike class which hold both behaviour and state a module can not be instantiated, but can be included in a class module War...

7. Lambdas and Blocks

###7.Lambdas and Blocks ####7.1 Lambdas in Ruby a lambda is just a function peculiarly(特别的) without a name lambda 就是个匿名函数 lambdas in ruby are also objects the last expression of a lambda is its re...

6. Ruby method

###6. Ruby method ####6.1 Being Methodical 调用对象的方法 puts 1.next #2 对象的method方法 参数为方法名的字符串形式返回一个对象 puts 1.method("next") # #<Method: Fixnum(Integer)#next> ne = 1.method("next") ne.call ...

5. Class and 面向对象的ruby

###5. Class and 面向对象的ruby ####5.1 类 输出对象的类型 puts 1.class #Fixnum puts "".class #String puts [].class #Array 类型判断 puts 1.is_a?(Integer) #t...