comparison 1-Ruby/arrays.rb @ 16:8d46064c9afc

Be a nice Ruby user and follow block convention for do/end vs {}
author IBBoard <dev@ibboard.co.uk>
date Tue, 03 Jan 2017 20:38:45 +0000
parents 9aa1eba404f0
children
comparison
equal deleted inserted replaced
15:ebb19742b98f 16:8d46064c9afc
12 puts "and indexers are methods: [1].methods.include?(:[]) = #{[1].methods.include?(:[])}" 12 puts "and indexers are methods: [1].methods.include?(:[]) = #{[1].methods.include?(:[])}"
13 # Note: we're using v1.9+ syntax - previously it was "….include?('[]')" 13 # Note: we're using v1.9+ syntax - previously it was "….include?('[]')"
14 puts "as is assignment to an array! [1].methods.include?(:[]=) = #{[1].methods.include?(:[]=)}" 14 puts "as is assignment to an array! [1].methods.include?(:[]=) = #{[1].methods.include?(:[]=)}"
15 puts "" 15 puts ""
16 puts "All funky non-ASCII methods for arrays:" 16 puts "All funky non-ASCII methods for arrays:"
17 [].methods.each { |method| 17 [].methods.each do |method|
18 if method !~ /[a-z]/ 18 if method !~ /[a-z]/
19 puts method 19 puts method
20 end 20 end
21 } 21 end
22 22
23 puts "" 23 puts ""
24 puts "Arrays are also stacks with push() and pop() methods!" 24 puts "Arrays are also stacks with push() and pop() methods!"