diff --git a/associative_arrays.rb b/associative_arrays.rb index 215cf5b..fd6e101 100644 --- a/associative_arrays.rb +++ b/associative_arrays.rb @@ -3,3 +3,7 @@ p aa.assoc("Someone") p aa.assoc("Bla") + +# Result: +# ["Someone", "1"] +# ["Bla", "2"] diff --git a/autovivification.rb b/autovivification.rb index 449fbfe..92d1593 100644 --- a/autovivification.rb +++ b/autovivification.rb @@ -3,3 +3,6 @@ deep[:a][:b][:c][:d] = 42 p deep + +# Result: +# {:a=>{:b=>{:c=>{:d=>42}}}} diff --git a/blocks_can_take_blocks.rb b/blocks_can_take_blocks.rb index cad30bb..4ad1994 100644 --- a/blocks_can_take_blocks.rb +++ b/blocks_can_take_blocks.rb @@ -6,3 +6,6 @@ end object.show_var_and_block { :block } + +# Result: +# [:var, #] diff --git a/bubbling_up_thread_errors.rb b/bubbling_up_thread_errors.rb index a80ee7e..d22eab2 100644 --- a/bubbling_up_thread_errors.rb +++ b/bubbling_up_thread_errors.rb @@ -7,3 +7,6 @@ loop do sleep end + +# Result: +# ./bubbling_up_thread_errors.rb:4:in `block in
': Ops, we cannot continue (RuntimeError) diff --git a/case_on_ranges.rb b/case_on_ranges.rb index fe0eb4e..32f2f72 100644 --- a/case_on_ranges.rb +++ b/case_on_ranges.rb @@ -9,3 +9,7 @@ when 65..Float::INFINITY p 'You are too old' end + +# Result: +# 55 +# "You are at the right age" diff --git a/count_all_objects.rb b/count_all_objects.rb index 9884c05..0a5f1bb 100644 --- a/count_all_objects.rb +++ b/count_all_objects.rb @@ -1,3 +1,23 @@ require 'pp' pp ObjectSpace.count_objects + +# Result: +# {:TOTAL=>30163, +# :FREE=>1007, +# :T_OBJECT=>39, +# :T_CLASS=>534, +# :T_MODULE=>24, +# :T_FLOAT=>4, +# :T_STRING=>9290, +# :T_REGEXP=>70, +# :T_ARRAY=>2231, +# :T_HASH=>53, +# :T_STRUCT=>1, +# :T_BIGNUM=>2, +# :T_FILE=>14, +# :T_DATA=>966, +# :T_MATCH=>1, +# :T_COMPLEX=>1, +# :T_NODE=>15896, +# :T_ICLASS=>30} diff --git a/cycle.rb b/cycle.rb index 21a5605..84da596 100644 --- a/cycle.rb +++ b/cycle.rb @@ -1,3 +1,6 @@ ring = %w[one two three].cycle p ring.take(5) + +# Result: +# ["one", "two", "three", "one", "two"] diff --git a/easiest_database_pstore.rb b/easiest_database_pstore.rb index 2f7d2cc..b70ae9c 100644 --- a/easiest_database_pstore.rb +++ b/easiest_database_pstore.rb @@ -20,3 +20,10 @@ p 'People %p' % db['people2'] p 'Money %p' % db['money2'] end + +# Result: +# "People \"Someone\"" +# "Money 400" +# "SECOND PERSON" +# "People \"Someone2\"" +# "Money 300" diff --git a/easiest_database_pstore_yaml.rb b/easiest_database_pstore_yaml.rb index 8dab8a2..1cb2436 100644 --- a/easiest_database_pstore_yaml.rb +++ b/easiest_database_pstore_yaml.rb @@ -20,3 +20,10 @@ p 'People %p' % db['people2'] p 'Money %p' % db['money2'] end + +# Result: +# "People \"Someone\"" +# "Money 400" +# "SECOND PERSON" +# "People \"Someone2\"" +# "Money 300" diff --git a/enable_ruby_warnings.rb b/enable_ruby_warnings.rb index 8dcfd42..09604db 100644 --- a/enable_ruby_warnings.rb +++ b/enable_ruby_warnings.rb @@ -9,3 +9,7 @@ def var p WarnMe.new.var + +# Result: +# ./enable_ruby_warnings.rb:5: warning: instance variable @var not initialized +# 42 diff --git a/fast_memoization_fibonacci.rb b/fast_memoization_fibonacci.rb index 8fe5e9b..48c388b 100644 --- a/fast_memoization_fibonacci.rb +++ b/fast_memoization_fibonacci.rb @@ -4,3 +4,6 @@ p fibonacci[300] + +# Result: +# 222232244629420445529739893461909967206666939096499764990979600 diff --git a/fetch_data.rb b/fetch_data.rb index c86ff24..32a3f48 100644 --- a/fetch_data.rb +++ b/fetch_data.rb @@ -6,3 +6,10 @@ params.fetch(:missing) + +# Result: +# 42 +# 42 +# 42 +# ./fetch_data.rb:7:in `fetch': key not found: :missing (KeyError) +# from ./fetch_data.rb:7:in `
' diff --git a/get_random_data.rb b/get_random_data.rb index 46377b1..b5ed679 100644 --- a/get_random_data.rb +++ b/get_random_data.rb @@ -5,3 +5,9 @@ p p SecureRandom.hex(20) p SecureRandom.base64(20) + +# Result: +# 0.7851536586163714 +# 46 +# "3efb674fbc2ba390856c15489652e75e8afff6d1" +# "yFv0WzugzFC6/D71teVe1Y5r1kU=" diff --git a/inject.rb b/inject.rb index fd21b34..be151a9 100644 --- a/inject.rb +++ b/inject.rb @@ -1,2 +1,14 @@ p (1..10).inject{ |r,e| p [r,e]; r*2} + +# Result: +# [1, 2] +# [2, 3] +# [4, 4] +# [8, 5] +# [16, 6] +# [32, 7] +# [64, 8] +# [128, 9] +# [256, 10] +# 512 diff --git a/iterating_over_specific_types.rb b/iterating_over_specific_types.rb index baa046e..830b3db 100644 --- a/iterating_over_specific_types.rb +++ b/iterating_over_specific_types.rb @@ -1,3 +1,11 @@ ObjectSpace.each_object(String) do |object| p object end + +# Result: +# "block in dependent_specs" +# "block in dependent_specs" +# "block (3 levels) in dependent_gems" +# "block (3 levels) in dependent_gems" +# ... (huge output suppressed) +# "This rdoc is bundled with Ruby" diff --git a/lambda_your_own_syntax.rb b/lambda_your_own_syntax.rb index a541bcc..c16406e 100644 --- a/lambda_your_own_syntax.rb +++ b/lambda_your_own_syntax.rb @@ -6,3 +6,6 @@ module Kernel l = λ { p :called } l.call + +# Result: +# :called diff --git a/print_formatted_with_debug.rb b/print_formatted_with_debug.rb index 00cdba4..b4456df 100644 --- a/print_formatted_with_debug.rb +++ b/print_formatted_with_debug.rb @@ -4,3 +4,5 @@ def debug(name, content) debug "Num", 42 +# Result: +# "Num: 42" diff --git a/ruby_debug_flag.rb b/ruby_debug_flag.rb index c059f9d..6b22eb6 100644 --- a/ruby_debug_flag.rb +++ b/ruby_debug_flag.rb @@ -7,3 +7,9 @@ def var end p var + 2 + +# Result: +# ruby_debug_flag.rb:2: warning: instance variable @var not initialized +# "var is 40" +# ruby_debug_flag.rb:2: warning: instance variable @var not initialized +# 42 diff --git a/shortcut_variable_interpolation.rb b/shortcut_variable_interpolation.rb index 46999f2..19e9ef8 100644 --- a/shortcut_variable_interpolation.rb +++ b/shortcut_variable_interpolation.rb @@ -3,3 +3,6 @@ $global = :global p "#@instance, #@@class, and #$global variables don't need braces" + +# Result: +# "instance, class, and global variables don't need braces" diff --git a/struct_without_assignment.rb b/struct_without_assignment.rb index 68ccbec..0428d31 100644 --- a/struct_without_assignment.rb +++ b/struct_without_assignment.rb @@ -6,3 +6,6 @@ def full franzejr = Struct::Name.new("Franze", "Jr") p franzejr.full + +# Result: +# "Franze Jr" diff --git a/super_magic_key_word.rb b/super_magic_key_word.rb index a05372d..48b0a83 100644 --- a/super_magic_key_word.rb +++ b/super_magic_key_word.rb @@ -11,3 +11,6 @@ def show_args(a,b,c) end Child.new.show_args(:a, :b, :c) + +# Result: +# [:a, :b, :c] diff --git a/super_magic_key_word2.rb b/super_magic_key_word2.rb index d12674d..a790030 100644 --- a/super_magic_key_word2.rb +++ b/super_magic_key_word2.rb @@ -12,3 +12,6 @@ def show_args(a,b,c) #Everything goes up, including the block Child.new.show_args(:a, :b, :c) { :block } + +# Result: +# [:a, :b, :c, #] diff --git a/super_magic_key_word3.rb b/super_magic_key_word3.rb index 453a5bb..6062072 100644 --- a/super_magic_key_word3.rb +++ b/super_magic_key_word3.rb @@ -13,3 +13,6 @@ def show_args(a,b,c) #Nothing goes up Child.new.show_args(:a, :b, :c) + +# Result: +# [nil] diff --git a/super_magic_key_word4.rb b/super_magic_key_word4.rb index a2160d1..f3bdb18 100644 --- a/super_magic_key_word4.rb +++ b/super_magic_key_word4.rb @@ -13,3 +13,6 @@ def show_args(a,b,c) #Nothing goes up, neither the block Child.new.show_args(:a, :b, :c) { :block } + +# Result: +# [nil] diff --git a/super_magic_key_word5.rb b/super_magic_key_word5.rb index b24abf0..90ea2ed 100644 --- a/super_magic_key_word5.rb +++ b/super_magic_key_word5.rb @@ -13,3 +13,7 @@ def delegate p DelegateToMe.new.extend(DelegateIfCan).delegate p DontDelegateToMe.new.extend(DelegateIfCan).delegate + +# Result: +# "Modified: DelegateToMe" +# "DelegateIfCan" diff --git a/tail_call.rb b/tail_call.rb index 842fd4d..288ab34 100644 --- a/tail_call.rb +++ b/tail_call.rb @@ -12,3 +12,5 @@ def factorial(n, result=1) end p factorial(100000) + +# Result: diff --git a/trigger_irb_as_needed.rb b/trigger_irb_as_needed.rb index 5e6d042..1c341a5 100644 --- a/trigger_irb_as_needed.rb +++ b/trigger_irb_as_needed.rb @@ -13,3 +13,7 @@ def my_program_context p "Current value: #{my_program_context.value}" sleep 1 end + +# Result: +# "Current value: 40" +# "Current value: 40" diff --git a/unused_variable_format.rb b/unused_variable_format.rb index dcce1c2..84dfa6d 100644 --- a/unused_variable_format.rb +++ b/unused_variable_format.rb @@ -5,3 +5,8 @@ ].each do |name,_,_| p name end + +# Result: +# "Someone" +# "Someone2" +# "Someone3" diff --git a/variables_from_a_regex.rb b/variables_from_a_regex.rb index 8fedf7e..293d37a 100644 --- a/variables_from_a_regex.rb +++ b/variables_from_a_regex.rb @@ -1,3 +1,6 @@ if /\A(?\w+),\s*(?\w+)\z/ =~ "Franze, Jr" puts "#{first} #{last}" end + +# Result: +# Franze Jr diff --git a/zip.rb b/zip.rb index a71a00d..8d69569 100644 --- a/zip.rb +++ b/zip.rb @@ -4,3 +4,9 @@ letters.zip(numbers) do |letter, number| p(letter: letter, number: number) end + +# Result: +# {:letter=>"a", :number=>1} +# {:letter=>"b", :number=>2} +# {:letter=>"c", :number=>3} +# {:letter=>"d", :number=>nil}