- 浏览: 793612 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (651)
- Java (39)
- Java 初学者小问题 (66)
- 设计模式 (7)
- 项目管理 (3)
- 数据库 (1)
- 算法 (2)
- Java practices (6)
- Effective Java2读书笔记 (78)
- Linux (2)
- programming ruby 读书笔记 (5)
- Core Java Ninth Edition Volume I 读书笔记 (15)
- Pro Git 读书笔记 (12)
- Git (3)
- Maven in Action 读书笔记 (20)
- Web (12)
- 非技术类书籍 (11)
- 电影 (40)
- Web Cache (1)
- jquery (0)
- 历史 (4)
- Dive Into HTML5 读书笔记 (13)
- 三国演义小学毕业考 (79)
- 高效能人士的7个习惯 读书笔记 (12)
- Java Performance 读书笔记 (3)
- Protocol Buffer 学习笔记 (6)
- Mongo DB 学习笔记 (7)
- Morphia 学习笔记 (7)
- Algorithms -- Princeton 学习笔记 (13)
- String研究 (10)
- Hadoop: The Definitive Guide 读书笔记 (3)
- Java与模式读书笔记 (5)
- Date研究 (3)
- The Roman Empire 听课笔记 (4)
- Algorithms -- Standford 学习笔记 (16)
- Core Java Ninth Edition Volume II 读书笔记 (9)
- Thinking in Java 4th Edition 读书笔记 (21)
- Node : Up and Running 学习笔记 (5)
- Eloquent Javascript (8)
- Smashing Node.js 读书笔记 (1)
- Algorithms II -- Standford 学习笔记 (19)
- Algorithm II -- Princeton 学习笔记 (14)
- 网络安全 (2)
- Javascript (4)
- 正则表达式 (1)
- JAVA 7/8 (15)
- JVM (10)
- NodeJS (1)
- 鸟哥的linux私房菜读书笔记 (14)
- Web Service (1)
- The art of programming (9)
- Introduction to Algorithm 读书笔记 (4)
- Java 源码阅读 (0)
- Spring in Action 读书笔记 (2)
- Java Network Programming 读书笔记 (2)
最新评论
-
心存高远:
谢谢作者分享,刚好看到这里不太明白,现在茅塞顿开。不过runt ...
关于 Maven的传递依赖的理解 -
sxlkk:
851228082 写道甚至在某次技术会议现场遇到《Maven ...
关于 Maven的传递依赖的理解 -
851228082:
851228082 写道a----compile----b-- ...
第五章 坐标和依赖 -
851228082:
a----compile----b-----provided- ...
第五章 坐标和依赖 -
851228082:
甚至在某次技术会议现场遇到《Maven in action》的 ...
关于 Maven的传递依赖的理解
1. Ruby is a genuine object-oriented language. Everything you manipulate is an object, and the results of those manipulations are themselves objects.
2. Every object has a unique object identifier (abbreviated as object ID).
3. puts is a standard Ruby method that writes its argument(s) to the console, adding a newline after each.
4. In Ruby, the ability to determine an absolute value is built into numbers:
num = -123 puts num.abs
5. You don’t need semicolons at the ends of statements as long as you put each statement on a separate line.
6. Ruby comments start with a # character and run to the end of the line.
7. Methods are defined with the key word def , followed by the method name and the method’s parameters between parentheses. (In fact, the parentheses are optional) Ruby doesn’t use braces to delimit the bodies of compound statements and definitions. Instead, you simply finish the method body with the keyword end .
8. You don’t need to declare a variable, instead you can use a variable directly.
9. Ruby has many ways to create a string object, but probably the most common is to use string literals, which are sequences of characters between single or double quotation marks. The difference between the two forms is the amount of processing Ruby does on the string while constructing the literal. In the single-quoted case, Ruby does very little. In the double-quoted case, Ruby does more work. First, it looks for substitutions (sequences that start with a backslash character) and replaces them with some binary value. The most common of these is \n , which is replaced with a newline character. The second thing that Ruby does with double-quoted strings is expression interpolation. Within the string, the sequence #{expression} is replaced by the value of expression.
10. capitalize method, defined for all strings, is to return the string with a leading uppercase letter.
11. The value returned by a Ruby method is the value of the last expression evaluated, so we can get rid of the temporary variable and the return statement altogether.
12. The first characters of a name indicate how the name is used. Local variables, method parameters, and method names should all start with a lowercase letter or an underscore. Global variables are prefixed with a dollar sign ($), and instance variables begin with an “at” sign (@). Class variables start with two “at” signs (@@). Finally, class names, module names, and constants must start with an uppercase letter.
13. Arrays and hashes are indexed collections, accessible using a key. With arrays, the key is an integer, whereas hashes support any object as a key. Both arrays and hashes grow as needed to hold new elements. It’s more efficient to access array elements, but hashes provide more flexibility. Any particular array or hash can hold objects of differing types.
14. You can create and initialize a new array object using an array literal—a set of elements between square brackets. Ruby array indices start at zero.
15. nil is an object, just like any other, that happens to represent nothing.
16. Sometimes creating arrays of words can be a pain, what with all the quotes and commas. Fortunately, Ruby has a shortcut; %w does just what we want:
a = %w{ ant bee cat dog elk }
17. A hash literal uses braces rather than square brackets. The literal must supply two objects for every entry: one for the key, the other for the value. The key and value are normally separated by => .The thing to the left of the => is the key, and the thing to the right is the corresponding value. Hashes are indexed using the same square bracket notation as arrays. A hash by default returns nil when indexed by a key it doesn’t contain.
18. p method that writes the values to the console works like puts but displays values such as nil explicitly.
19. To create a hash with default value as 0:
Hash.new(0)
20. Symbols are simply constant names that you don’t have to pre-declare and that are guaranteed to be unique. A symbol literal starts with a colon and is normally followed by some kind of name. There’s no need to assign some kind of value to a symbol. Ruby guarantees that no matter where it appears in your program, a particular symbol will have the same value.
21. You can use name: value pairs to create a hash if the keys are symbols.
inst_section = { cello: 'string', clarinet: 'woodwind', drum: 'percussion', oboe: 'woodwind', trumpet: 'brass', violin: 'string' }
22. Ruby uses the keyword end to signify the end of a body of all the control structures.
23. Most statements in Ruby return a value, which means you can use them as conditions. And Ruby treats nil as a false value in conditions.
24. The kernel method gets returns the next line from the standard input stream or nil when the end of the file is reached.
25. Ruby statement modifiers are a useful shortcut if the body of an if or while statement is just a single expression. Simply write the expression, followed by if or while and the condition:
puts "Danger, Will Robinson" if radiation > 3000
26. In Ruby, you typically create a regular expression by writing a pattern between slash characters (/pattern/ ).
27. The pipe character “| ” means “either the thing on the right or the thing on the left”. \s , matches a whitespace character (space, tab, newline, and so on); \d , which matches any digit; and \w , matches any character that may appear in a typical word. A dot “. ” matches (almost) any character.
28. The match operator =~ can be used to match a string against a regular expression. If the pattern is found in the string, =~ returns its starting position; otherwise, it returns nil .
line = gets if line =~ /Perl|Python/ puts "Scripting language mentioned: #{line}" end
29. T he part of a string matched by a regular expression can be replaced with different text using one of Ruby’s substitution methods: sub which is to replace the first matched text and gsub which is to replace all the matched text.
line.sub(/Perl/, 'Ruby')
30. Code blocks are chunks of code you can associate with method invocations, almost as if they were parameters. You can use code blocks to implement callbacks (but they’re simpler than Java’s anonymous inner classes), to pass around chunks of code (but they’re more flexible than C’s function pointers), and to implement iterators.
31. Code blocks are just chunks of code between braces or between do and end . The braces bind more tightly than the do /end pairs. What is becoming a Ruby standard is to use braces for single-line blocks and do /end for multiline blocks.
32. All you can do with a block is associate it with a call to a method. You do this by putting the start of the block at the end of the source line containing the method call. If the method has parameters, they appear before the block. A method can then invoke an associated block one or more times using the Ruby yield statement. You can think of yield as being something like a method call that invokes the block associated with the call to the method containing the yield .
33. You can provide arguments to the call to yield , and they will be passed to the block. Within the block, you list the names of the parameters to receive these arguments between vertical bars (|params...| ):
who_says_what {|person, phrase| puts "#{person} says #{phrase}"}
34. Code blocks are used throughout the Ruby library to implement iterators, which are methods that return successive elements from some kind of collection.
35.
[ 'cat', 'dog', 'horse' ].each {|name| print name, " " } 5.times { print "*" } 3.upto(6) {|i| print i } ('a'..'e').each {|char| print char }
Here we ask an array to call the block once for each of its elements. Then, object 5 calls a block five times. Rather than use for loops, in Ruby we can ask the number 3 to call a block, passing in successive values until it reaches 6 . Finally, the range of characters from a to e invokes a block using the method each .
36. puts writes its arguments with a newline after each; print also writes its arguments but with no newline. Both can be used to write to any I/O object, but by default they write to standard output.
37. printf prints its arguments under the control of a format string (just like printf in C or Perl).
38. T he array ARGV contains each of the arguments passed to the running program. The variable ARGF is a special kind of I/O object that acts like all the contents of all the files whose names are passed on the command line (or standard input if you don’t pass any filenames).
发表评论
-
Sharing Functionality: Inheritance, Modules, and Mixins
2012-09-01 12:39 10021. When puts needs t ... -
Containers, Blocks, and Iterators
2012-08-20 14:55 10201. The class Array holds ... -
Classes, Objects, and Variables
2012-08-17 22:25 10541. initializ ... -
Getting Started
2011-11-18 10:16 9911. Interactive Ruby—is t ...
相关推荐
The new edition of this book provides the same excellent introduction to Ruby as the previous editions plus updates for the newest version of Ruby 2.3. This book can also be used as a textbook or ...
You'll also receive updates when significant changes are made, new chapters as they're written, and the final ebook bundle. Head First Ruby uses an engaging, active approach to learning that goes ...
** 和 **Proc#to_proc** 的区分:`Proc.new` 创建的 Proc 对象默认是非 lambda 行为,而 `->` 创建的是 lambda 行为。 4. **Hash Destructuring**:在函数调用时可以使用哈希解构,将参数直接映射到变量。 5. **...
application = WIN32OLE.new('Excel.Application') application.visible = TRUE workbook = application.Workbooks.Add(); worksheet = workbook.Worksheets(1); worksheet.Range('A1:D1').value = ['North','South...
例如,你可以使用 `Redis.new` 创建客户端实例,`set` 和 `get` 方法进行键值对的存储和读取,`keys` 查找匹配的键,`lpush` 和 `rpop` 对于列表数据类型的操作,以及 `subscribe` 和 `publish` 实现消息队列。...
ApplicationInsights-Ruby 是使用 Ruby 开发的 Microsoft Application Insights SDK 。 分享 window._bd_share_config = { "common": { ...
redis = Redis.new ``` 接着,你可以执行各种操作,比如设置和获取键值: ```ruby redis.set('key', 'value') value = redis.get('key') # => "value" ``` 对于Redis的其他功能,如哈希、列表、集合和有序集合,`...
Ruby installer 1.9.3 .exe new sass
### Ruby 数组详解 #### 一、Ruby 语言概述 Ruby 是一种动态、面向对象的高级编程语言,以其简洁明了的语法而闻名。它强调程序员的生产力与代码的可读性,被誉为“程序员最好的朋友”。Ruby 具备强大的元编程能力,...
##### 第2章:Ruby.new 本章介绍了Ruby的基本概念和安装过程,让初学者能够快速上手。它覆盖了Ruby环境的搭建、解释器的使用等基础知识,为后续章节的学习打下坚实的基础。 ##### 第3章:类、对象与变量 这一章深入...
- **第2章:Ruby.new**:介绍Ruby环境的搭建及基本使用。 - **第3章:Classes, Objects, and Variables**:深入探讨类、对象和变量的概念与用法。 - **第4章:Containers, Blocks, and Iterators**:讲解容器数据...
### Ruby 变量详解 #### 一、引言 在深入了解 Ruby 变量之前,我们需要先对 Ruby 这门语言有一个基本的认知。Ruby 是一种高度动态的、面向对象的脚本语言,它由日本人松本行弘(Matsumoto Yukihiro)在 1995 年...
ruby-lastfm, Last.fm Web服务的ruby 接口 ruby-lastfm Last.fm Web服务 v2.0的ruby 接口概要require 'lastfm'lastfm = Lastfm.new(api_key, api_secret)token = l
The new edition of this book provides the same excellent introduction to Ruby as the first edition plus updates for the newest version of Ruby, including the addition of the Sinatra and Ramaze web ...
在压缩包文件“rpm-master”中,可能包含了New Relic的Ruby代理(Agent)源代码,这个代理会被集成到Ruby应用程序中,负责收集性能数据并上报到New Relic服务器。通过分析和理解这个源码,开发者可以更深入地了解New...