Changes between Version 1 and Version 2 of SummaryRuby
- Timestamp:
- Jan 11, 2014, 4:47:05 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SummaryRuby
v1 v2 111 111 end 112 112 113 114 113 115 # Inheritance: 114 116 # create a superclass called Doctro from the Person's class (inheritance) … … 171 173 my_circle = Drawing::Circle.new 172 174 175 176 173 177 # 174 178 # Extensions … … 186 190 187 191 192 188 193 # 189 194 # Modules … … 233 238 hello 234 239 240 241 235 242 # 236 243 # Flow examples … … 260 267 puts "universe is broken" 261 268 end 269 262 270 263 271 # case … … 272 280 end 273 281 282 274 283 # ternary operator 275 284 puts x > 10 ? "higher than 10" : "lower or equal to 10" … … 287 296 288 297 298 # 289 299 # variable substitution ways: 300 # 290 301 foo = "12345678901234567890" 291 302 # puts the first 10 chars in different ways: … … 296 307 297 308 309 310 # 298 311 # Arrays: 312 # 299 313 a = [1, 2, 3, "four"] 300 314 a << 5 … … 303 317 puts a.include?("four") # true 304 318 319 320 321 # 305 322 # Hashes (associative arrays) 323 # 306 324 dictionary = { 'cat' => 'feline animal', 307 325 'dog' => 'canine animal', … … 315 333 316 334 335 336 # 317 337 # Code blocks 338 # 318 339 def each_vowel 319 340 %w{a e i o u}.each { |vowel| yield vowel } … … 355 376 356 377 378 379 # 380 # Debug 381 # 357 382 # If you want to run a script in debug mode, "ruby -r debug script.rb", use 358 # step, break, watch, cont, etc... 383 # step, break, watch, cont, etc... 384 # you can found some basic example in the book "beginning ruby" pag. 190 359 385 360 386 … … 381 407 382 408 catch(:done) { routine(3) } 409 383 410 384 411 … … 432 459 # dynamic code execution of eval 433 460 obj.new_method do def new_method ; puts 'born new method in an alive object' ; end ; end 434 435 461 436 462 … … 476 502 477 503 478 479 480 481 482 483 504 # 484 505 # Unit Testing … … 550 571 551 572 573 552 574 # Using Files 553 575 puts "It exists" if File.exist?("text.txt") … … 583 605 584 606 585 # 586 # Docs 607 608 # 609 # Documentation (generating your own) 610 # 611 # Similar to doxygen, just write comments using this syntax and by running 612 # "rdoc file.rb" (or yard?) you will obtain nicely html's generated 587 613 # 588 614 # In documentations, "Array#sample" means the instance method of a class … … 621 647 # 622 648 623 # run "rdoc file.rb" to generate the documentation624 649 # by adding in a class or element "#:nodoc: all" there's no docs generated (for 625 650 # the entire class) 626 651 627 652 628 629 #630 # Debug631 #632 # - ruby -d foo.rb: see page 190 of "begining ruby" which has some basic demo633 653 634 654