# HG changeset patch # User IBBoard # Date 1483475925 0 # Node ID 8d46064c9afc2c59be8ccb91a5278141df019c3f # Parent ebb19742b98fa3662decfb62fd819e6a0caeaab9 Be a nice Ruby user and follow block convention for do/end vs {} diff -r ebb19742b98f -r 8d46064c9afc 1-Ruby/arrays-irb.output --- a/1-Ruby/arrays-irb.output Tue Jan 03 20:36:16 2017 +0000 +++ b/1-Ruby/arrays-irb.output Tue Jan 03 20:38:45 2017 +0000 @@ -35,11 +35,11 @@ arrays.rb(main):016:0> puts "All funky non-ASCII methods for arrays:" All funky non-ASCII methods for arrays: => nil -arrays.rb(main):017:0> [].methods.each { |method| +arrays.rb(main):017:0> [].methods.each do |method| arrays.rb(main):018:1* if method !~ /[a-z]/ arrays.rb(main):019:2> puts method arrays.rb(main):020:2> end -arrays.rb(main):021:1> } +arrays.rb(main):021:1> end == [] []= diff -r ebb19742b98f -r 8d46064c9afc 1-Ruby/arrays.rb --- a/1-Ruby/arrays.rb Tue Jan 03 20:36:16 2017 +0000 +++ b/1-Ruby/arrays.rb Tue Jan 03 20:38:45 2017 +0000 @@ -14,11 +14,11 @@ puts "as is assignment to an array! [1].methods.include?(:[]=) = #{[1].methods.include?(:[]=)}" puts "" puts "All funky non-ASCII methods for arrays:" -[].methods.each { |method| +[].methods.each do |method| if method !~ /[a-z]/ puts method end -} +end puts "" puts "Arrays are also stacks with push() and pop() methods!" diff -r ebb19742b98f -r 8d46064c9afc 1-Ruby/object-all-things-2-irb.output --- a/1-Ruby/object-all-things-2-irb.output Tue Jan 03 20:36:16 2017 +0000 +++ b/1-Ruby/object-all-things-2-irb.output Tue Jan 03 20:38:45 2017 +0000 @@ -2,10 +2,10 @@ object-all-things-2.rb(main):002:0* object-all-things-2.rb(main):003:0* objects = [ 4, 3.14, 'Pi', 'π', false, true ] => [4, 3.14, "Pi", "π", false, true] -object-all-things-2.rb(main):004:0> objects.each { |obj| +object-all-things-2.rb(main):004:0> objects.each do |obj| object-all-things-2.rb(main):005:1* puts "#{obj} (#{obj.class})" object-all-things-2.rb(main):006:1> obj.methods.each { |method| puts " #{method}" } -object-all-things-2.rb(main):007:1> } +object-all-things-2.rb(main):007:1> end 4 (Fixnum) to_s inspect diff -r ebb19742b98f -r 8d46064c9afc 1-Ruby/object-all-things-2.rb --- a/1-Ruby/object-all-things-2.rb Tue Jan 03 20:36:16 2017 +0000 +++ b/1-Ruby/object-all-things-2.rb Tue Jan 03 20:38:45 2017 +0000 @@ -1,7 +1,7 @@ #! /usr/bin/env ruby objects = [ 4, 3.14, 'Pi', 'π', false, true ] -objects.each { |obj| +objects.each do |obj| puts "#{obj} (#{obj.class})" obj.methods.each { |method| puts " #{method}" } -} +end diff -r ebb19742b98f -r 8d46064c9afc 1-Ruby/truthiness-irb.output --- a/1-Ruby/truthiness-irb.output Tue Jan 03 20:36:16 2017 +0000 +++ b/1-Ruby/truthiness-irb.output Tue Jan 03 20:38:45 2017 +0000 @@ -3,11 +3,11 @@ truthiness.rb(main):003:0* values = [ true, false, 1, 0, -1, 'some string', '', nil ] => [true, false, 1, 0, -1, "some string", "", nil] truthiness.rb(main):004:0> -truthiness.rb(main):005:0* values.each { |val| +truthiness.rb(main):005:0* values.each do |val| truthiness.rb(main):006:1* text = if val == nil then "nil" else "'#{val}'" end truthiness.rb(main):007:1> puts "Val #{text} is truthy" if val truthiness.rb(main):008:1> puts "Val #{text} is falsy" unless val -truthiness.rb(main):009:1> } +truthiness.rb(main):009:1> end Val 'true' is truthy Val 'false' is falsy Val '1' is truthy diff -r ebb19742b98f -r 8d46064c9afc 1-Ruby/truthiness.rb --- a/1-Ruby/truthiness.rb Tue Jan 03 20:36:16 2017 +0000 +++ b/1-Ruby/truthiness.rb Tue Jan 03 20:38:45 2017 +0000 @@ -2,8 +2,8 @@ values = [ true, false, 1, 0, -1, 'some string', '', nil ] -values.each { |val| +values.each do |val| text = if val == nil then "nil" else "'#{val}'" end puts "Val #{text} is truthy" if val puts "Val #{text} is falsy" unless val -} +end