Ray's playground

 

随笔分类 -  Ruby

1 2 下一页

Namespaces, Source Files, and Distribution(Chapter 16 of Programming Ruby)
摘要:Putting code inside a module or class is a good way of separating it from other code.Ruby’s Math module is a good example—it defines constants such as Math::PI and Math::Eand methods such ... 阅读全文

posted @ 2010-07-16 21:28 Ray Z 阅读(171) 评论(0) 推荐(0)

Ruby and Its World(Chapter 15 of Programming Ruby)
摘要:RubyGems is a standardized packaging and installation framework for Ruby libraries andapplications. RubyGems makes it easy to locate, install, upgrade, and uninstall Ruby packages.  Rake was initially... 阅读全文

posted @ 2010-07-11 20:54 Ray Z 阅读(157) 评论(0) 推荐(0)

When Trouble Strikes(Chapter 14 of Programming Ruby)
摘要:Ruby comes with a debugger, which is conveniently built into the base system. You canrun the debugger by invoking the interpreter with the -r debug option, along with any otherRuby options and the nam... 阅读全文

posted @ 2010-07-06 20:53 Ray Z 阅读(131) 评论(0) 推荐(0)

Unit Testing(Chapter 13 of Programming Ruby)
摘要:RomanCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1classRoman2MAX_ROMAN=49993definitialize(value)4ifvalue<=0||value>MAX_ROMAN5fail"Romanvalue... 阅读全文

posted @ 2010-07-06 12:53 Ray Z 阅读(167) 评论(0) 推荐(0)

Fibers, Threads, and Processes(Chapter 12 of Programming Ruby)
摘要:[代码] 阅读全文

posted @ 2010-07-05 20:25 Ray Z 阅读(122) 评论(0) 推荐(0)

Basic Input and Output(Chapter 11 of Programming Ruby)
摘要:[代码] 阅读全文

posted @ 2010-07-05 12:54 Ray Z 阅读(142) 评论(0) 推荐(0)

Exceptions, Catch, and Throw(Chapter 10 of Programming Ruby)
摘要:[代码] 阅读全文

posted @ 2010-07-04 17:41 Ray Z 阅读(147) 评论(0) 推荐(0)

Expressions(Chapter 9 of Programming Ruby)
摘要:break terminates the immediately enclosing loop; control resumes at the statement followingthe block. redo repeats current iteration of the loop from the start but without reevaluatingthe condition or... 阅读全文

posted @ 2010-07-03 20:24 Ray Z 阅读(133) 评论(0) 推荐(0)

More About Methods(Chapter 8 of Programming Ruby)
摘要:Methods that return a boolean result (socalledpredicate methods) are often named with a trailing ?.  Methods that are “dangerous,” or that modify their receiver, may be named with a traili... 阅读全文

posted @ 2010-06-29 00:05 Ray Z 阅读(188) 评论(0) 推荐(0)

Standard Types(Chapter 6 of Programming Ruby)
摘要:[代码]  In Ruby,these sequences are created using the . . and . . . range operators. The two-dot form createsan inclusive range, and the three-dot form creates a range that excludes the specified highva... 阅读全文

posted @ 2010-06-28 13:00 Ray Z 阅读(140) 评论(0) 推荐(0)

Sharing Functionality: Inheritance, Modules, and Mixins(Chapter 5 of Programming Ruby)
摘要:Modules are a way of grouping together methods, classes, and constants. Modules give youtwo major benefits:  • Modules provide a namespace and prevent name clashes.  • Modules support the ... 阅读全文

posted @ 2010-06-28 12:43 Ray Z 阅读(281) 评论(0) 推荐(0)

Containers, Blocks, and Iterators(Chapter 4 of Programming Ruby)
摘要:[代码]injectCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1[1,3,5,7].inject(0){|sum,element|sum+element}#=>162[1,3,5,7].inject(1){|product,element|... 阅读全文

posted @ 2010-06-28 12:38 Ray Z 阅读(171) 评论(0) 推荐(0)

Classes, Objects, and Variables(Chapter 3 of Programming Ruby)
摘要:classCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1classBookInStock2attr_reader:isbn3attr_accessor:price4definitialize(isbn,price)5@isbn=isbn6@pric... 阅读全文

posted @ 2010-06-27 16:44 Ray Z 阅读(161) 评论(0) 推荐(0)

Ruby.new(Chapter 2 of Programming Ruby)
摘要:Ruby uses a convention that may seem strange at first: the first characters of a name indicatehow the name is used. Local variables, method parameters, and method names should allstart with a lowercas... 阅读全文

posted @ 2010-06-26 21:50 Ray Z 阅读(168) 评论(0) 推荐(0)

Recipe 1.10. Changing the Case of a String
摘要:[代码]Output: HELLO, I'M RAY    hello, i'm ray    Hello, i'm ray    HELLO, i'm RAY    hello, I'M rayThe upcase and downcase methods force all letters in the string to upper-or lowercase, respectively. T... 阅读全文

posted @ 2009-11-15 14:02 Ray Z 阅读(177) 评论(0) 推荐(0)

Recipe 1.9. Processing a String One Word at a Time
摘要:[代码]Output: dogs3dog2[代码]Output: dogs3dog2   quite1f.b.i1the1fella1that1man-about-town1he's1 阅读全文

posted @ 2009-11-09 12:34 Ray Z 阅读(186) 评论(0) 推荐(0)

Recipe 1.8. Processing a String One Character at a Time
摘要:If you're processing an ASCII document, then each byte corresponds to one character. Use String#each_byte to yield each byte of a string as a number, which you can turn into a one-character string:[代码... 阅读全文

posted @ 2009-11-06 23:22 Ray Z 阅读(238) 评论(0) 推荐(0)

Recipe 1.7. Converting Between Strings and Symbols
摘要:To turn a symbol into a string, use Symbol#to_s, or Symbol#id2name, for which to_s is an alias.[代码]Output:a_symbol    AnotherSymbol    Yet another symbol!You usually reference a symbol by just typing ... 阅读全文

posted @ 2009-11-05 22:57 Ray Z 阅读(189) 评论(0) 推荐(0)

Recipe 1.6. Converting Between Characters and Values
摘要:To see the ASCII code for a specific character as an integer, use the ? operator:[代码]Output: 97To see the integer value of a particular in a string, access it as though it were an element of an array:... 阅读全文

posted @ 2009-11-04 12:49 Ray Z 阅读(180) 评论(0) 推荐(0)

Recipe 1.5. Representing Unprintable Characters
摘要:Ruby gives you a number of escaping mechanisms to refer to unprintable characters. By using one of these mechanisms within a double-quoted string, you can put any binary character into the string.[代码]... 阅读全文

posted @ 2009-11-03 22:40 Ray Z 阅读(183) 评论(0) 推荐(0)

1 2 下一页

导航