annotate 1-Ruby/arrays-irb.output @ 29:9c7af76fdbd0

Print isn't PrinLn, so add some \n characters to the output
author IBBoard <dev@ibboard.co.uk>
date Wed, 06 Sep 2017 18:36:02 +0100
parents 8d46064c9afc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 arrays.rb(main):001:0> #! /usr/bin/env ruby
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 arrays.rb(main):002:0*
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 arrays.rb(main):003:0* animals = ['lions', 'tigers', 'bears']
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 => ["lions", "tigers", "bears"]
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 arrays.rb(main):004:0>
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 arrays.rb(main):005:0* # Default "puts" for array is one element per line
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 arrays.rb(main):006:0* puts animals
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 lions
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 tigers
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 bears
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 arrays.rb(main):007:0>
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 arrays.rb(main):008:0* puts "Accessing undefined indexes gives nil" if animals[10] == nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 Accessing undefined indexes gives nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 arrays.rb(main):009:0> puts "Negative indexes also work (like Python): -1 = #{animals[-1]}"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 Negative indexes also work (like Python): -1 = bears
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 arrays.rb(main):010:0> puts "And you get slices/ranges: 1..2 = #{animals[1..2]}"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 And you get slices/ranges: 1..2 = ["tigers", "bears"]
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 arrays.rb(main):011:0> puts "1..2 is even an object: #{(1..2).class}"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 1..2 is even an object: Range
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 arrays.rb(main):012:0> puts "and indexers are methods: [1].methods.include?(:[]) = #{[1].methods.include?(:[])}"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 and indexers are methods: [1].methods.include?(:[]) = true
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 arrays.rb(main):013:0> # Note: we're using v1.9+ syntax - previously it was "….include?('[]')"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 arrays.rb(main):014:0* puts "as is assignment to an array! [1].methods.include?(:[]=) = #{[1].methods.include?(:[]=)}"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 as is assignment to an array! [1].methods.include?(:[]=) = true
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 arrays.rb(main):015:0> puts ""
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 arrays.rb(main):016:0> puts "All funky non-ASCII methods for arrays:"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 All funky non-ASCII methods for arrays:
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 => nil
16
8d46064c9afc Be a nice Ruby user and follow block convention for do/end vs {}
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
38 arrays.rb(main):017:0> [].methods.each do |method|
14
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 arrays.rb(main):018:1* if method !~ /[a-z]/
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 arrays.rb(main):019:2> puts method
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 arrays.rb(main):020:2> end
16
8d46064c9afc Be a nice Ruby user and follow block convention for do/end vs {}
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
42 arrays.rb(main):021:1> end
14
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 ==
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 []
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 []=
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 <<
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 <=>
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 +
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 *
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 -
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 &
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 |
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 ===
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 =~
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 !~
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 !
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 !=
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 => [: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__]
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 arrays.rb(main):022:0>
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 arrays.rb(main):023:0* puts ""
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 arrays.rb(main):024:0> puts "Arrays are also stacks with push() and pop() methods!"
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 Arrays are also stacks with push() and pop() methods!
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 => nil
9aa1eba404f0 Add some poking of arrays
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 arrays.rb(main):025:0>