Ruby Ruby Under a Microscope Pat Shaughnessy 20150109 b5891c1 (m-sl b-n bc-n)
Title of English-language original: Ruby Under a Microscope ISBN 978-1-59327-527-3, published by No Starch Press, Inc. Copyright 2014 by Pat Shaughnessy. Japanese-language edition copyright 2014 by Ohmsha, Ltd. All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording or by any information storage retrieval system, without permission from No Starch Press, Inc. E-mail kaihatu@ohmsha.co.jp FAX 03-3293-2825
Ruby Ruby Under a Microscope Pat Pat Rubyist Peter Cooper (@peterc), Editor of Ruby Inside and Ruby Weekly Ruby Xavier Noria (@fxn), Ruby Hero, Ruby on Rails Core Team Member Pat Shaughnessy Ruby Santiago Pastorino (@spastorino), WyeWorks Co-Founder, Ruby on Rails Core Team Member Ruby Ruby 3 Vlad Ivanovic (@vladiim), Digital Strategist at Holler Sydney Ruby David Deryl Downey (@daviddwdowney), Founder of CyberSpace Technologies Group
vi xv xvii xix xxi................................... xxi Ruby............................. xxii Ruby........................... xxii.................................. xxiii 1 3 Ruby...................... 4 parser_yylex........................... 7 1-1 Ripper Ruby. 9 Ruby............ 12 LALR.............. 14 Ruby................. 21 Bison....................... 23 1-2 Ripper Ruby. 25..................................... 31 2 33 Ruby 1.8........................ 34 Ruby 1.9................... 35 Ruby............ 36....................... 41 Ruby AST.............. 45 2-1 YARV...................... 48
vii.............................. 49.................... 52.................... 54 2-2.................. 56..................................... 58 3 Ruby 61 YARV Ruby............. 62 Ruby...... 63....................... 66 YARV.................... 68 3-1 Ruby 2.0/Ruby 1.9 Ruby 1.8...... 71 Ruby............... 74........................ 74............. 77........................... 78 C EP................... 81 3-2....................... 83....................... 87..................................... 89 4 91 Ruby if.................... 92.............. 95............................. 96.................... 98 4-1 Ruby... 99 send Ruby.................. 101............... 101 11...................... 102........................... 104................... 105......................... 106 attr_reader attr_writer................. 107 attr_reader attr_writer. 108 4-2 Ruby..... 109..................................... 113
viii 5 115 Ruby.......................... 116 klass ivptr......................... 117 2............... 118........................ 119 Ruby........... 120....... 121 RBasic RObject........... 122 Ruby........................... 123 5-1................................ 124 RClass......................... 127.................................. 130 vs................ 132....................... 134.................................. 137 RClass......................... 138 RClass..................... 140 5-2 Ruby.......... 141..................................... 144 6 147 Ruby................. 148...................... 148.............. 150 Ruby..................... 151........................... 152.................. 154 Ruby....................... 156................... 156................... 157 Ruby............. 158 2........ 158....... 160 Module#prepend......................... 162 Ruby Module#prepend.......... 166 6-1.......... 167
ix........... 168. 169.......................... 170 Ruby..... 171................................... 173................. 173 Ruby..... 175 Ruby..................... 176........... 177.. 179 Ruby.................... 181 6-2 Ruby.......... 182 Ruby................ 183..................................... 184 7 Ruby 187 Ruby...................... 188.................. 188................. 191 7-1.... 192...... 194............................ 195........................ 196 Ruby 196 7-2 1.. 197 57 67......... 200 Ruby................ 202 7-3......... 205 Ruby 2.0.................. 210..................................... 211 8 Lisp 213 Ruby.................... 214 Ruby........... 215 1975.................... 218 rb_block_t rb_control_frame_t.............. 221 8-1 while each.. 222
x Proc............... 226 vs....................... 227 Ruby......... 228 Ruby..................... 230 Ruby.................. 233 Proc.......................... 235 8-2....... 238 1............. 241..................................... 243 9 245....................... 246....................... 246 248.. 250.............. 251. 253 Refinements....................... 254 Refinements....................... 256 9-1 self 257 self................... 258 self....................... 259 self..................... 260 self................... 261 eval instance_eval binding..... 263....................... 263 binding eval................... 266 instance_eval........................ 268 Ruby 1........ 269 instance_eval self............. 271 instance_eval.............................. 272 Ruby. 273 9-2.......... 275 define_method........................ 275............... 276..................................... 278
xi 10 JRuby JVM Ruby 281 MRI JRuby................... 282 JRuby........ 284 JRuby.................. 285 Ruby Java............ 288 10-1 JRuby JIT.............. 290.............................. 291 -J-XX:+PrintCompilation............. 292 JIT JRuby.............. 293 JRuby MRI....................... 295 JRuby MRI.......... 295........................ 297 10-2............ 300............. 300.............................. 302................... 302............. 304..................................... 305 11 Rubinius Ruby Ruby 309 Rubinius....................... 310......................... 312 Ruby Ruby............... 313 Rubinius.................... 313 Ruby C++.................... 315 Ruby C++....... 317 11-1 MRI Rubinius........... 317 Rubinius..................... 318 Rubinius MRI........................... 321 MRI.......................... 321 RArray......................... 323 Rubinius........................ 324 11-2 Rubinius Array#shift........... 325 Array#shift.......................... 326 Array#shift........................ 327..................................... 330
xii 12 MRI JRuby Rubinius GC 333 3.............. 334 MRI.......... 334............................. 334 MRI.................. 335................................. 336 MRI........ 337................................ 338............................. 339 RVALUE........................... 339.................... 340 12-1 MRI........ 340 MRI.................. 342 MRI GC........................ 343 GC............ 344 JRuby Rubinius GC....................... 348 GC.................................. 348....................... 349......................... 350 Eden.............................. 352 GC.................................. 352............................ 353........ 353....................... 353........... 354............................. 355 GC.................................... 357....... 357............................ 359 JVM 3 GC....................... 360 12-2 JRuby Verbose GC.............. 362 GC....................... 363................................... 365..................................... 365 A Ruby 369 YARV Yet Another RubyVM........................ 369 YARV.............................. 370
xiii YARV........................... 371 Ruby..................... 372 373 375 382
xv *1 SF 1880 5 21 5 Ruby Ruby Ruby Ruby Ruby CRuby JRuby Rubinius Ruby *2 Ruby 1.7 YARV Ruby Ruby 2014 10 *1 1971 *2 Ruby 2002
xvii tenderlove Ruby Ruby on Rails Pat Pat Ruby Under a Microscope *3 Ruby Ruby Ruby Pat Ruby Ruby Ruby Ruby Ruby Ruby Aaron Patterson <3 <3 <3 <3 *3
xix Satty Bhens Alex Rothenberg Daniel Higginbotham Xavier Noria 6-1 Santiago Pastorino Jill Caporrimo Prajakta Thakur Yvannova Montalvo Divya Ganesh Yanwing Wong SWAT Peter Cooper Peter No Starch Press Ruby Under a Microscope Ruby 1 Julianne Jigour Riley Hoffman Alison Law Charles Nutter JVM Aaron Patterson Bill Pollock 1 1
xxi Ruby Ruby Ruby ruby Enter Ruby Ruby Lisp Smalltalk Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby C C C Ruby Ruby
xxii note C Ruby C Ruby C C Ruby Ruby Ruby C Ruby C Ruby Ruby Ruby Ruby Ruby Ruby Ruby Ruby 1993 Matz Ruby Matz Ruby MRI MRI Matz Ruby RubyMotion MacRuby IronRuby Topaz JRuby C Rubinius Ruby Matz mruby Ruby mruby Ruby
xxiii Ruby JRuby Rubinius 10 11 12 Ruby MRI 1 Ruby 2 Ruby 3 Ruby 4 Ruby Ruby if...else while...end 5 Ruby Ruby 6 Ruby Ruby 7 Ruby Ruby MRI 8 Ruby Lisp 9 Ruby Ruby 10 Java Ruby JRuby JRuby Ruby Java JVM
xxiv 11 Ruby Rubinius Rubinius Ruby Ruby 12 GC Rubinius JRuby MRI GC Ruby Ruby 1600 Ruby Ruby
Ruby
3 1 Ruby 1 2 3 Rails Sinatra Ruby Ruby 3 ruby Ruby 1-1 Ruby YARV AST 1-1 Ruby Ruby Ruby Ruby Ruby Ruby Yet Another Ruby Virtual Machine YARV Ruby
4 1 3 Ruby 2 Ruby note 1993 Ruby Matz s Ruby Interpreter MRI Ruby Ruby MRI Ruby Enterprise Edition MagLev MacRuby RubyMotion mruby 10 11 12 Ruby 2 JRuby Rubinius Ruby Ruby simple.rb 1-1 Ruby simple.rb 10.times do n puts n end 1-2 simple.rb 1-1 $ ruby simple.rb 0 1 2 3 --snip-- ruby simple.rb ENTER Ruby simple.rb Ruby simple.rb Ruby 1-2
Ruby 5 1 0. t i m e s d o n 1-2 simple.rb Ruby 1-3 Ruby 1 0. t i m e s d o n 1-3 Ruby Ruby C C Ruby Ruby 1 1-4 0 1 0. t i m e s d o n 1-4 Ruby 1-5 1 0. t i m e s d o n 1-5 Ruby Ruby 1-6 Ruby t
6 1 1 0. t i m e s d o n 1-6 Ruby Ruby Ruby 1-7 1 0. t i m e s d o n 1-7 Ruby Ruby tinteger tinteger. t i m e s d o n 10 1-8 Ruby 2 tinteger Ruby 1 2 1-9 tinteger 10. t i m e s d o n 1-9 Ruby 1-10 Ruby times