Symbols & Numbers

Symbols & Numbers

INDEX Symbols & Numbers = (assignment operator), 6 =begin, 4 & (ampersand), 166, 167 =begin rdoc, 345–346 && (and operator), 85, 93 =end, 4, 345–346 * (asterisk), 251–252, 260 == (equal-to operator), 56, 136 *?, 260 ===, 88, 92 @ (at sign), 23, 100 => (assoc operator), 141 @@ (class variables), 23, 100 =~, 250. See also regular expressions \ (line continuation character), 297 ! (exclamation mark) \B, 260 at end of methods, 131 \b , 260 as not operator, 85, 86, 93 \D , 260 != (not-equals operator), 86 \d, 260 // (delimiters), 250 \S, 260 > (greater-than sign), 56 \s, 260 # (hask mark), for comments, 4 \W, 260 #{}, in strings, 2 \w, 260 < (less-than sign), 56 ^ (caret), 251, 260. See also regular indicating descent, 17–18 expressions <=> (comparison operator), 54, 55, : (colon) 77, 207, 223 in case statements, 90 << instead of then, 84 append operator, 37, 63, 129 in symbols), 181 concatenation method, 130–131 :: (scope resolution operator), 30, with heredocs, 45 185, 193, 208–209, 330 and singletons, 109, 117 {} (curly brackets) <<-, with heredocs, 45 as delimiters, 161 <%%>. See Rails, tags in regular expressions, 260 <%=. See Rails, tags $ (dollar sign), 251–252, 260. See (), parentheses, also regular expressions; avoiding ambiguity, 85, 137, 162 variables optional, 2, 22 $`, 255. See also regular expressions in regular expressions, 260 $:, 202 and super, 18 $!, 141 %/, 35 $/ (record separator), 42 %d, 43 $', 255. See also regular expressions %f, 43 $~, 256. See also regular expressions %o, 43 The Book of Ruby © 2011 by Huw Collingbourne %p, 43 clear, 57 %Q, 35 clone, 53 %q, 35 collect, 159, 190 %r, 250. See also regular expressions compact, 57, 58 %s, 43 compact!, 57 %W, 46, 49 concatenating, 63–64 %w, 49 copying, 53 %x, 36, 43 creating, 48–50 . (period), 260 delete, 57 + (plus sign), 252, 260 delete_at, 57 +=, 23 each, 159 +?, 260 expressions in, 49 ? (question mark), 256, 260 of filenames, 49 ?..:, as shorthand for if..then..else, flatten, 57, 58 87, 269 flatten!, 57 [] (square brackets), 260 indexing, 52–53 | (vertical pipe), 260 iterators, 51–52, 159 || (or operator), 85, 93 length, 47 3rd Rail, 357 methods, 57–58 multidimensional, 50 A nested, 50 reverse, 57 accessor methods, 19 reverse!, 57 Ada, xviii sort, 57 Adobe Flex, 322 sort!, 57 alias, 199–200 sorting, 54–55 all_symbols, 190 of strings, 49 ambiguity, xix. See also testing for equality, 53–54 parentheses () treating hashes as, 63 avoiding, 123, 199 ASCII character codes, testing, 215 hashes and blocks, 162 assert, 293, 295 line breaks, 285, 296 assert_block, 295 ampersand (&), 166, 167 assert_equal, 292, 295 ancestors. See class hierarchy assert_in_delta, 295 and operator (&&), 85, 93 assert_instance_of, 295 Apache, 302, 358 assert_kind_of, 294 Aptana RadRails, 358 assert_match, 295 arguments assert_nil, 295 by reference, 129 assert_no_match, 295 default, 124 assert_not_equal, 295 passing, 134–135 assert_nothing_raised, 296 by value, 134 assert_nothing_thrown, 296 arrays, 47–48 assert_not_nil, 295 &, 57 assert_not_same, 295 -, 57 assert_operator, 296 <<, 57 assert_raise, 296 +, 57 assert_raises, 296 appending, 63–64 assert_respond_to, 296 362 INDEX The Book of Ruby © 2011 by Huw Collingbourne assert_same, 296 returning from methods, assert_send, 296 175–176 assert_thrown, 296 Ruby 1.9, 155 assignment operator (=), 6 scope of, 168, 177 assignments, 135–136 sorting with, 54 multiple, 133 blogs, 316–321 parallel, 133 books, on Ruby, 353–354 associative arrays. See hashes Boolean operators, 85–86, 93–94 assoc operator (=>), 141 negation, 86 asterisk (*), 251–252, 260 precedence, 93 at sign (@), 23, 100 side effects, 94 attr_accessor, 21, 327 break, 75, 90, 158–159 attributes, 20–23 breaking code over a line, 297. See attr_reader, 20, 182 also line breaks attr_writer, 20, 182 breakpoints, 289. See also debugging build_message, 296 B bytes, reading, 247 \B, 260 \b, 260 C backquotes. See strings call, 187 backtrace, 150. See also exceptions camel case, xviii BasicObject, 29, 106, 142 capitalization. See strings =begin, 4 caret (^), 251, 260. See also regular begin..end, 73, 152 expressions =begin rdoc, 345–346 case sensitivity, 2 bindings, 334–336 case statements, 89 block_given?, 171 return values, 92 block parameters, 70, 157, 168, selectors, 91 170, 179 catch, 94–96, 152–153 blocks, 70, 155–156. See also fibers character codes. See strings {}, 70, 161 chomp, 42 call, 162 chop, 42 creating methods from, 332, 337 classes, 6 creating objects from, 162 descending from Object, 106 do..end, 70, 158 vs. modules, 192, 205 and for loops, 180 as objects, 104 and instance variables, 176–177 open, 30 and iterating arrays, 159–161 partial, 30–31 as iterators, 172–174 singleton, 108 and line breaks, 156–157 class_eval, 329–331 and local variables, 177–180 class hierarchy, 15–16 nested, 165 class methods, 97, 98, 122. See also parameters, 70, 157, 168, methods 170, 179 class_variable_get, 331–333 passing as named arguments, class variables, 23, 99 165–170 class_variables, 332 precedence, 170–171 class_variable_set, 331–333 INDEX 363 The Book of Ruby © 2011 by Huw Collingbourne clone, 60 default, 60 closures, 163–164. See also blocks default=, 60 collect, 76, 273. See also arrays; defined?, 179 Enumerable define_method, 188, 330, 337 colon (:) delete, 62 in case statements, 90 descendants, 15–16 instead of then, 84 destructors, 11 in symbols, 181 dictionaries. See hashes comments, 4 Digging Deeper in code examples, xvii arguments, passing, 134–135 multiline, 4 arrays, 63 single line, 4 assertions, 295–296 Comparable, 55, 206, 207 assignments, 135–136 comparison operator (<=>), 54, 55, begin..end, 152 77, 207, 223 blocks and closures, 175–180 conditional statements, 83. See Boolean operators, 93–94 also case statements; catch..throw, 94, 152–153 if modifiers debuggers, 297 constants, 90 each, 81 accessing with ::, 30, 207, 208 Enumerable, 76–81 inside classes, 30 equality, testing for, 136 const_get, 333 exceptions, 152–153 constructors extending objects, 210 initialize, 10–11, 104–105 freezing objects, 211, 342–343 new, 10–11, 104–105 hashes, 63 overriding, 104–105 heredocs, 45–46 const_set, 333 line breaks, 296–297 Controller, 305–307, 323 Marshal version numbers, copying files, 217–218. See also files 246–248 cp, 218 method accessibility, 114–116 curly brackets, {} modules, 205–210 as delimiters, 161 MVC, 322–323 in regular expressions, 260 Rails folders, 323 custom comparisons, 77 recursions, 224–226 regular expressions, 260–261 D Ruby frameworks, 324 scope resolution, 208–209 \D, 260 string literals, 46 \d, 260 superclasses, 25–30 %d, 43 symbols, 190, 261 databases, 358–359 threads, 278–281 data hiding, 128 unit testing, 295–296 debuggers, visual, 226, 297, 357–358 YAML, 237–238 debugging, 286 yield, 81 breakpoints, 289 directories, navigating in, 219. See with Ruby Debugger, 289 also files watchpoints, 290 Dir.foreach, 220 def, 5 Dir.getwd, 144 364 INDEX The Book of Ruby © 2011 by Huw Collingbourne do, 69, 156 eval, 186, 327. See also dynamic documenting Ruby. See RDoc programming do..end, 156, 158. See also blocks example programs, xix dollar sign ($), 251–252, 260. See exception hierarchy, 142 also regular expressions; exceptions, 140 variables and $!, 141 downto, 70–71 associating with variable dynamic programming, 188, 325 name, 141 adding methods, 337 backtrace, 150 adding methods to classes, 332 begin..end, omitting, 152 creating classes at runtime, 333 creating custom messages for, creating objects at runtime, 333 150–151 and embedded evaluation, 326 custom, raising, 151 eval, 327 displaying as strings, 148 freezing objects, 342 else, 145–146 monkey patching, 330 ensure, 144 removing methods, 337 Errno constants, 147 self-modifying programs, multiple, 142 326, 328 NoMethodError, 142 writing programs at runtime, 340 raise, 149 rescue, 140 E retry, 148 RuntimeError, 150 each, 68, 79, 159, 234 subclassing, 151 vs. for, 68 TypeError, 142, 342 and yield, 81 ZeroDivisionError, 141 ebooks, on Ruby, 355 exclamation mark (!) editors, Ruby, 357–358 at end of methods, 131 Eiffel, xviii, 6 as not operator, 85, 86, 93 else, 145. See also exceptions extend, 210 Embedded Ruby (ERb), 313, 314 encapsulation, 8, 128 breaking, 131, 333 F end, 5 %f, 43 =end, 4, 345–346 fibers ensure, 145. See also exceptions alive?, 276 Enumerable, 76–81, 206 and blocks, 275 collect, 76 dead, 276 include?, 76 FiberError, 276 including in a class, 79 parameters, 276 max, 76 resume, 275 min, 76, 78 and threads, 275 overriding methods, 80 yield, 275 equal?, 135, 136, 183 File methods, 98 equality, testing for, 136 files equal-to operator (==), 56, 136 backing up, 219 ERb (Embedded Ruby), 313, 314 closing, 214–216 Errno, 146–147. See also exceptions copying, 217 INDEX 365 The Book of Ruby © 2011 by Huw Collingbourne files (continued) H and directories, 217 Hansson, David Heinemeier, 316 eof, 215 hashes, 58 exist?, 217 copying, 60 foreach, 254, 258 creating, 58–59 handles, 215 and curly brackets, 161–162 modes, 214 has_key?, 62 opening, 214 has_value?, 62 processing using regular indexing into, 60 expressions, 258–259 items in reading/writing text, 215, 259 deleting, 62 saving data to YAML, 231 finding position of, 62 size of, 220 merging, 62 calculating, 219 methods, 62 sorting by, 222 order of elements, 60, 229 as a subclass of IO, 214 sort, 223 FileTest, 206 sorting, 61 FileUtils, 218 treating as arrays, 63 Fixnums, 136. See also integers hask mark (#), for comments, 4 flunk, 296 heredocs, 45–46 foreach, 213 HTML, tags, 309, 311. See also Rails for..in loops, 51 for loops, 67–70 and arrays, 71 I and blocks, 180 id2name, 186 and local variable scoping, 180 IDEs (integrated development envi- and multiple iterator ronments), 283, 357–358 arguments, 71 if..else, 84 and ranges, 69 if..elsif, 86 format strings, 43 if modifiers, 88–89 freeze, 211, 342–343 if..then, 4–5 frozen?, 211, 342 if..then..else, 84 functions, 157–158. See also methods include, 194. See also modules and module_function, 209 include?, 76, 88.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us