Changes between Version 1 and Version 2 of SummaryRuby


Ignore:
Timestamp:
Jan 11, 2014, 4:47:05 PM (11 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SummaryRuby

    v1 v2  
    111111end
    112112
     113
     114
    113115# Inheritance:
    114116# create a superclass called Doctro from the Person's class (inheritance)
     
    171173my_circle = Drawing::Circle.new
    172174
     175
     176
    173177#
    174178# Extensions
     
    186190
    187191
     192
    188193#
    189194# Modules
     
    233238hello
    234239
     240
     241
    235242#
    236243# Flow examples
     
    260267    puts "universe is broken"
    261268end
     269
    262270
    263271# case
     
    272280end
    273281
     282
    274283# ternary operator
    275284puts  x > 10 ? "higher than 10" : "lower or equal to 10"
     
    287296
    288297
     298#
    289299# variable substitution ways:
     300#
    290301foo = "12345678901234567890"
    291302# puts the first 10 chars in different ways:
     
    296307
    297308
     309
     310#
    298311# Arrays:
     312#
    299313a = [1, 2, 3, "four"]
    300314a << 5
     
    303317puts a.include?("four") # true
    304318
     319
     320
     321#
    305322# Hashes (associative arrays)
     323#
    306324dictionary = { 'cat' => 'feline animal',
    307325               'dog' => 'canine animal',
     
    315333
    316334
     335
     336#
    317337# Code blocks
     338#
    318339def each_vowel
    319340    %w{a e i o u}.each { |vowel| yield vowel }
     
    355376
    356377
     378
     379#
     380# Debug
     381#
    357382# 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
    359385
    360386
     
    381407
    382408catch(:done) { routine(3) }
     409
    383410
    384411
     
    432459# dynamic code execution of eval
    433460obj.new_method do def new_method ; puts 'born new method in an alive object' ; end ; end
    434 
    435461
    436462
     
    476502
    477503
    478 
    479 
    480 
    481 
    482 
    483504#
    484505# Unit Testing
     
    550571
    551572
     573
    552574# Using Files
    553575puts "It exists" if File.exist?("text.txt")
     
    583605
    584606
    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
    587613#
    588614# In documentations, "Array#sample" means the instance method of a class
     
    621647#
    622648
    623 # run "rdoc file.rb" to generate the documentation
    624649# by adding in a class or element "#:nodoc: all" there's no docs generated (for
    625650# the entire class)
    626651
    627652
    628 
    629 #
    630 # Debug
    631 #
    632 #   - ruby -d foo.rb:  see page 190 of "begining ruby" which has some basic demo
    633653
    634654