Script started on Wed Nov 5 11:39:37 2014 bash-3.2$ irb irb(main):001:0> nums = [1, 2 , 3 4, 5] => [1, 2, 3, 5] irb(main):002:0> nums => [1, 2, 3, 5] irb(main):003:0> nums[1] => 2 irb(main):004:0> nums[1,3] => [2, 3, 5] irb(main):005:0> nums[-2] => 3 irb(main):006:0> nums => [1, 2, 3, 5] irb(main):007:0> nums[4]=17 => 17 irb(main):008:0> nums => [1, 2, 3, 5, 17] irb(main):009:0> nums[10] = "ten" => "ten" irb(main):010:0> nums => [1, 2, 3, 5, 17, nil, nil, nil, nil, nil, "ten"] irb(main):011:0> nums.class => Array irb(main):012:0> nums.methods => [:inspect, :to_s, :to_a, :to_h, :to_ary, :frozen?, :==, :eql?, :hash, :[], :[]=, :at, :fetch, :first, :last, :concat, :<<, :push, :pop, :shift, :unshift, :insert, :each, :each_index, :reverse_each, :length, :size, :empty?, :find_index, :index, :rindex, :join, :reverse, :reverse!, :rotate, :rotate!, :sort, :sort!, :sort_by!, :collect, :collect!, :map, :map!, :select, :select!, :keep_if, :values_at, :delete, :delete_at, :delete_if, :reject, :reject!, :zip, :transpose, :replace, :clear, :fill, :include?, :<=>, :slice, :slice!, :assoc, :rassoc, :+, :*, :-, :&, :|, :uniq, :uniq!, :compact, :compact!, :flatten, :flatten!, :count, :shuffle!, :shuffle, :sample, :cycle, :permutation, :combination, :repeated_permutation, :repeated_combination, :product, :take, :take_while, :drop, :drop_while, :bsearch, :pack, :entries, :sort_by, :grep, :find, :detect, :find_all, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :all?, :any?, :one?, :none?, :min, :max, :minmax, :min_by, :max_by, :minmax_by, :member?, :each_with_index, :each_entry, :each_slice, :each_cons, :each_with_object, :chunk, :slice_before, :lazy, :nil?, :===, :=~, :!~, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] irb(main):013:0> nums.length => 11 irb(main):014:0> nums.methods.length => 169 irb(main):015:0> nums.methods.class => Array irb(main):017:0> nums => [1, 2, 3, 5, 17, nil, nil, nil, nil, nil, "ten"] irb(main):018:0> nums[5,9]=42 => 42 irb(main):019:0> nums => [1, 2, 3, 5, 17, 42] irb(main):020:0> nums[2]=123 => 123 irb(main):021:0> nums => [1, 2, 123, 5, 17, 42] irb(main):022:0> nums.sort => [1, 2, 5, 17, 42, 123] irb(main):023:0> nums[2]="ii" => "ii" irb(main):024:0> nums => [1, 2, "ii", 5, 17, 42] irb(main):025:0> nums.sort ArgumentError: comparison of String with 5 failed from (irb):25:in `sort' from (irb):25 from /usr/local/bin/irb:11:in `
' irb(main):026:0> irb(main):026:0> nums => [1, 2, "ii", 5, 17, 42] irb(main):027:0> nums[5]=["an", "array', "of", "strings"] => ["an", "array", "of", "strings"] irb(main):028:0> nums => [1, 2, "ii", 5, 17, ["an", "array", "of", "strings"]] irb(main):029:0> things = Hash.new => {} irb(main):030:0> things => {} irb(main):031:0> things = {"this" => 42, "that" -=> "something else"]} => {"this"=>42, "that"=>"something else"} irb(main):032:0> things => {"this"=>42, "that"=>"something else"} irb(main):033:0> things["this"] => 42 irb(main):034:0> things["what"] = "?" => "?" irb(main):035:0> things => {"this"=>42, "that"=>"something else", "what"=>"?"} irb(main):036:0> nums => [1, 2, "ii", 5, 17, ["an", "array", "of", "strings"]] irb(main):037:0> nums = [1,2,3,4,5,6,7] => [1, 2, 3, 4, 5, 6, 7] irb(main):038:0> nums => [1, 2, 3, 4, 5, 6, 7] irb(main):039:0> things.methods => [:rehash, :to_hash, :to_h, :to_a, :inspect, :to_s, :==, :[], :hash, :eql?, :fetch, :[]=, :store, :default, :default=, :default_proc, :default_proc=, :key, :index, :size, :length, :empty?, :each_value, :each_key, :each_pair, :each, :keys, :values, :values_at, :shift, :delete, :delete_if, :keep_if, :select, :select!, :reject, :reject!, :clear, :invert, :update, :replace, :merge!, :merge, :assoc, :rassoc, :flatten, :include?, :member?, :has_key?, :has_value?, :key?, :value?, :compare_by_identity, :compare_by_identity?, :entries, :sort, :sort_by, :grep, :count, :find, :detect, :find_index, :find_all, :collect, :map, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :first, :all?, :any?, :one?, :none?, :min, :max, :minmax, :min_by, :max_by, :minmax_by, :each_with_index, :reverse_each, :each_entry, :each_slice, :each_cons, :each_with_object, :zip, :take, :take_while, :drop, :drop_while, :cycle, :chunk, :slice_before, :lazy, :nil?, :===, :=~, :!~, :<=>, :class, :singleton_class, :clone, :dup, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :extend, :display, :method, :public_method, :singleton_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] irb(main):040:0> things.methods.length => 147 irb(main):041:0> nusms => [1, 2, 3, 4, 5, 6, 7] irb(main):042:0> nums.each { puts "boring" } boring boring boring boring boring boring boring => [1, 2, 3, 4, 5, 6, 7] irb(main):045:0> nums.each { | n | puts n }"exciting " + n }  . t o _ s exciting 1 exciting 2 exciting 3 exciting 4 exciting 5 exciting 6 exciting 7 => [1, 2, 3, 4, 5, 6, 7] irb(main):046:0> total = 0 => 0 irb(main):047:0> nums.each { |n | total += n } => [1, 2, 3, 4, 5, 6, 7] irb(main):048:0> total => 28 irb(main):049:0> things => {"this"=>42, "that"=>"something else", "what"=>"?"} irb(main):051:0> things.each { puts "a thing" } a thing a thing a thing => {"this"=>42, "that"=>"something else", "what"=>"?"} irb(main):052:0> things.each { | k, v | puts k, v } this 42 that something else what ? => {"this"=>42, "that"=>"something else", "what"=>"?"} irb(main):053:0> 3.times { puts "hello" } hello hello hello => 3 irb(main):054:0> 10.times { |n| puts "n = " + n.to_s } n = 0 n = 1 n = 2 n = 3 n = 4 n = 5 n = 6 n = 7 n = 8 n = 9 => 10 irb(main):055:0> def search(x, words) irb(main):056:1> words.each { | w | if x==w then return end } irb(main):057:2> puts "not found" irb(main):058:2> end bash-3.2$ exit Script done on Wed Nov 5 12:19:38 2014