COSA NON IGNORARE (ma non necessariamente leggere) DEL MANUALE ---------------------------------------- PArt I Facets of Ruby Ruby.new Classes Objects and Variables Containers Blocks and Iterators Standard Types (tranne Regular Espressions) More About Methods Expressions Modules (solo Namespaces) Basic Input and Output (tranne Talking to Networks) Part IV RUby Library Reference Array (tutto) Enumerable (tutto) String (parte) NUmeric, Integer, Float (tutto) Object (parte) Kernel (parte) Hash Range File IO RUBY REFERENCE -------------------------------------------------------------------------------------------------- COMPARISON OPERATORS <, <=, ==, !=, >=, >, between?(i,i), <=> BOOLEAN OPERATORS and(&&) or(||) not(!) BOOLEAN CONSTANTS true false CONDITIONAL EXECUTIONS ----------------------------------- 1) {} if condition 2) condition ? {} : {} 3) if condition then {} elsif condition then {} ... else {} end 4) case target when comparison then {} .... else {} end BLOCKS ------------------------------------------- begin o{ instruction ... end o} LOOPS -------------------------------------------------- loop {} {} while condition while condition ... end FUNCTION DEFINITION -------------------------------------- def function(par1,par2,... ) instructions ..... return value end CLASS DEFINITION ------------------------------------------ class Class def initialize() .... end def function() end .... end KERNEL ---------------------------------------- exit, p, puts, gets, rand NUMERIC ---------------------------------------------- operations +, -, *, **, /, % loops times, upto(i), downto(i), step(i,i) conversions to_f, to_s, to_i, chr rounding abs, round, ceil, floor STRING -------------------------------------------------- split(s,i) escape characters \n \t \\ \" \' string formatting %.4f %10d %-10s %% chomp(s) capitalize, downcase, upcase, swapcase center(i,s), ljust(i,s), rjust(i,s) strip,lstrip,rstrip ARRAY -------------------------------------------------- CREATING [o, o, ..] Array.new(i,o) Array.new(i) {Array.new(i,o)} TO STRING join(s) LOOPING each{|o| }, reverse_each{|o| } each_index{|i| } each_with_index {|o,i| } READING ONE [i] fetch(i,o), fetch(i) {|i| } max, min find {|o| } READING MANY [range] find_all{|o| } TO NUMBER size index(o), rindex(o) inject {|counter,i| } TO BOOLEAN include?(o) any?{} all?{} MODIFYING ELEMENTS [i]= [range]= fill(o,range) fill(range) {|i| } collect {|o| } SORTING reverse sort, sort_by {} INSERTING ELEMENTS push(o) unshift(o) insert(i,o) DELETING ELEMENTS pop shift delete_at(i) delete(o) delete_if {} ARRAY2ARRAY OPERATIONS +[] concatenation &[] intersection -[] difference |[] union *i repetition MATRICES zip transpose flatten assoc, rassoc OBJECT --------------------------------------------- class, dup, method_missing