Symbols & Numbers A

Symbols & Numbers A

ruby_02.book Page 267 Thursday, May 10, 2007 4:12 PM INDEX Symbols & Numbers \ (backslash), in regular expression, for literal characters, 144 %Q for instantiating Strings, 23, \W, in regular expression, for 108–109, 215–216, 219, 239, whitespace, 66 245, 248–250 { } (braces) %w for instantiating Arrays, 47, for blocks, 28 113, 115 for declaring Hash, 42 & (ampersand), for expressing blocks {x}, in regular expression, 79 and Procs, 105–106 - method (Hash), 93 ! (exclamation point), for destructive ||= operator, 77–78, 127 methods, 20, 22–23 | (pipe) character, in regular || (or) operator, 17 expression, 56 # character + method of Integers and Strings, 3–4 for comments, 14 + (plus sign), in regular for instance method, 234 expression, 62 #{} for wrapping expression to be = (equal sign), for assigning value to interpolated, 23 variable, 9 #! (shebang), 47 == operator, for equality testing, 14 $ (dollar sign), for bash prompt, 19 =begin rdoc, 22 * (asterisk), in irb prompt, 8 =end, 22 ** (asterisk doubled), for “to the <=> method (Comparable), 145, power of,” 72 150–151 /\d+/ in regular expression, for digits <% and %> tags, 211 only, 79 <%= tag, for printing expression, 214 :needs_data Symbol key, 116 99bottles.rb script, 20–25 :nitems Symbol key, 116 :unless0th Symbol key, 116 ? (question mark) A in predicate method names, 22 actionpack, warnings related to, 226 in regular expression, for optional Active Record, Rails dependence expressions, 144 on, 227 @ sign, for instance variable, 21–22 Agile Web Development with Rails @@ sign, for class variable, 82–84 (Thomas and Hansson), 227 [] (square brackets), for Array Akregator, 257, 259 instantiation, 5–6 alias method, 34–35, 199 [] method (Array), 68 all_photos method (ApplicationController), 243 ruby_02.book Page 268 Thursday, May 10, 2007 4:12 PM alpha_width method, 217 assert_nil method ampersand (&), for transforming (Test::Unit::Assertions), 140 blocks and Procs, 105–106 assert_raise method ancestors method (Module), 75 (Test::Unit::Assertions), 140 any? method (Enumerable), 44, 45 assert_respond_to method Apache webserver (Test::Unit::Assertions), 140 CGI for, 206 asterisk (*) set up to handle mod_ruby, 211–212 doubled, for “to the power of,” 72 web resources, 213 in irb prompt, 8 app directory for Rails, 230 Australian National University, 162 Apple operating systems, end-of-line marker, 51 B ARABIC_TO_ROMAN Hash, 84 ArgumentError exception, 106 backslash (\), for literal characters arguments, 8 within regular expression, 144 ARGV environment variable, 11, 16 bang (!), for destructive methods, arity, 106 22–23 flexible with Proc.new, 116–117 base, for exponentiation, 72 Array class, 27. See also Enumerable bash prompt, $ (dollar sign) for, 19 module begin keyword, 157 Children class inheritance =begin rdoc, 22 from, 171 Benchmark module and bm count_of method, 65 method, 129 detect method, 85–86 benchmarking, 128–131 each_with_index method, 58 Berners-Lee, Tim, 141 join method, 37 best_num method (Meta_Mutator), 180 matches_block method, 105 The Bible Code (Drosnin), 161 matching_compound_members method, 106 Bignum, 3 matching_members method, 105 Black, David Alan, Ruby for Rails, 227 nitems method, 116 The Blind Watchmaker (Dawkins), 168 rand method, 18, 27 blocks, 27 shuffle method, 27–28 ampersand (&) and, 105 shuffle! method, 27–28 do and end for, 28 for shuffled file playback, 26 Procs and, 102 sort_by method, 27, 145, 175 using Procs as, 110 as Strings, 36 bm (Benchmark) method, 129 array_join.rb script, 36–39 Boole, George, 6 Arrays, 5–6 Boolean type, 6 of Arrays, converting Hash into, 150 items evaluating to true, 7 converting item into, 6 Boolean values, methods returning, 22 creating single-word, 116 boolean_golf.rb script, 33–36 filtering, 103–108 bound variable, of inner lambda, 111 for return values, for factorial or braces ({ }) Fibonacci test, 125 for blocks, 28 instantiating with %w, 47, 113, 115 for declaring Hash, 42 ASCII values for characters, 171–172 browsers, dynamic stylesheet for, assert_instance_of method 215–218 (Test::Unit::Assertions), 140 Buffalo, NY, clement weather in November, 136 bytecode, 263 268 INDEX ruby_02.book Page 269 Thursday, May 10, 2007 4:12 PM C comma (,), adding to numbers, 75–81 C (programming language), 261–262 comments, # character for, 14 call method (Proc), 100 commify.rb script, 75–81 callback, 185 Common Gateway Interface CamelCase capitalization, 3 (CGI), 206 capital letters, for constants, 10 scripts, 207–210 carriage return, 15, 52 Comparable module, 145n Cascading Style Sheets (CSS), comparing Strings, 145 215–221, 246, 257 compiled language, 262 case, of names, 3 compose method casting, 4–5, 33 (Temperature_Converter), Boolean, 7 137 CD-ROM drive, Windows filesystem composition of functions, 134 access to, 20 implicit, 137 Celsius, vs. kelvins, 134 compounded filtering, Proc class for, CGI (Common Gateway 103–108 Interface), 206 Comprehensive Perl Archive scripts, 207–210 Network, 224 cgi library, 207 concatenation, 4, 80 cgi.out method, 209 Concurrent Versions System cgi.params Hash, 209 (CVS), 188 chaining methods, 5n, 80 constants, 10, 125 characters declaring inside class, 42 ASCII values for, 171–172 defining, 14–15 rotating in String, 68–70 construct_candidate method check_payday.rb script, 14–16 (ELS_Parser), 166 Cheese Shop (Python), 224 CONVERSIONS Hash, 135 Children class, 171 convert method select_fittest method, 171, 174, 175 class (Temperature_Converter), keyword, 21 135 method (Object), 3 converting class variables, 83–84 item into Array, 6 classes temperatures, 132–137 adding “helper” method to, 65 counting defining, 20–21 tags, 148–154 instances of, 2–3 words in file, 62–64 CLI parsers in Ruby, 39 count_of method (Array), 65 closing files, 17 create_english method code (Representable_In_English), placement in controller vs. 198 helper, 247 create_spanish method reusable, 40 (Representable_In_Spanish), testing execution speed of, 198 128–132 create_table method code coverage by testing, 139 (CreatePhotos), 239 command-line interface, 39–45 crontab, 19 Ruby options, 10 INDEX 269 ruby_02.book Page 270 Thursday, May 10, 2007 4:12 PM CSS (Cascading Style Sheets), double quotation marks in String, 215–221, 246, 257 %Q for, 23 currency conversion downcase method (String), 47 advanced, 90–98 download_new_rates method basic, 87–90 (CurrencyConverter), 94, 95 CurrencyConverter class Drosnin, Michael, The Bible Code, 161 download_new_rates method, 94, 95 dup method (Array), 37 get_rates method, 94 get_value method, 89 E get_xml_lines method, 94 initialize method, 89 -e flag, for Ruby, 56 output_rates method, 94 each method vs. map method, 66 pluralize method, 89 each_with_index method (Array), 58 save_rates_in_local_file! method, eager evaluation, 127 95–96 ELSes (equidistant letter currency_converter1.rb script, 87–90 sequences), 161 currency_converter2.rb script, 90–98 ELS_Parser class, 164 cv method (String), 84 initialize method, 165 prepare method, 165 reset_params method, 165 D search method, 165 Darwinian selection model, 168, 176 els_parser.rb script, 161–168 data-driven programming, 44 email signatures, dynamic content databases for Rails application, 229 for, 16–20 preparing, 238 empty? method (Wall), 22 Dawkins, Richard, The Blind =end, 22 Watchmaker, 168 end keyword declare_regexes_and_replacements for block, 28, 105 method, 144 for if expression, 7 with inject, 148 and method call, 61 def keyword, 8, 21 for method definitions, 24 definition list, output in HTML, 209 end-of-line marker, converting, 51–56 demo_els_parser.rb script, 167 END_OF_USAGE marker, 43 describe method (Him), 119 English units, converting, 132–137 describe2 method (Him), 119 Enumerable module destructive methods, 23 any? method, 44, 45 detect method (Array), 85–86 grep method, 65, 79 Dijkstra, Edsger, 263n inject method, 60–61, 65, 107 display method (Simple_CGI), 209 declare_regexes_and_replacements do keyword, for block, 28, 105 method with, 148 doc directory, for Rails, 230 ENV environment variable, 17 DocBook, 62, 141 environment variables and spell checker, 154 ARGV, 16 dollar sign ($), for bash prompt, 19 ENV, 17 DOM (Document Object Model), 157 for Ruby, 10 dont_play_file_proc Proc, 191 Epiphany web browser, 257 DOS-to-Unix EOL conversion, 56 equidistant letter sequences dos2unix.rb script, 51–56 (ELSes), 161 270 INDEX ruby_02.book Page 271 Thursday, May 10, 2007 4:12 PM eRuby, 211 File class exceptions new method, 17 ArgumentError, 106 well_formed_xml? method, 156–158 NoMethodError, 24, 39, 152 File objects, creating, 17 TypeError, 4 filename extensions, 213 XMLParserError, 158 files exchange rates, XML file for, 94–95 counting words in, 62–64 exclamation point (!), for destructive name for class definition, 21 methods, 22–23 filtering execution speed of code, testing, Proc class for, 102–103 128–132 Proc class for compounded, exit conditions, 74 103–108 exponentiation, 72 find method (Rails Models), 242 expressions, 2, 4 find_all method, 185 value appearing inside String, 23 first-class functions, 111 eXtensible HyperText Markup first_if_true method, 8 Language (XHTML), 142 fitness, measuring for survival of eXtensible Markup Language (XML), fittest, 173 87, 141 Fixnum module, 3 file for exchange rates, 94–95 flow control, 6–8 online tutorial, 90 format_float method (Precision), 80 validating, 156–158 format_int method (Precision), 79–80 external content, -r command-line Fowler, Martin, Refactoring: Improving flag for, 22 the Design of Existing Code, 124, 247 F free variables, 111 Friedl, Jeffrey, Mastering Regular

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    15 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