From: Matt Darby Date: Fri, 7 Oct 2011 19:56:59 +0000 (-0700) Subject: Merge pull request #53 from dandorman/hash_default_block_koans X-Git-Url: https://git.eng.unimelb.edu.au/public?a=commitdiff_plain;h=287142250797c8576c534061b51a826e93244552;hp=6acc65ac9294e89a35b70e8ee0efc31594cee551;p=ruby_koans.git Merge pull request #53 from dandorman/hash_default_block_koans Add koans addressing passing a block to Hash#initialize. --- diff --git a/koans/about_classes.rb b/koans/about_classes.rb index fce0be0..3fce646 100644 --- a/koans/about_classes.rb +++ b/koans/about_classes.rb @@ -126,7 +126,7 @@ class AboutClasses < EdgeCase::Koan # Why is this so? end - def test_different_objects_have_difference_instance_variables + def test_different_objects_have_different_instance_variables fido = Dog6.new("Fido") rover = Dog6.new("Rover") diff --git a/koans/about_control_statements.rb b/koans/about_control_statements.rb index f243ac8..71a7af0 100644 --- a/koans/about_control_statements.rb +++ b/koans/about_control_statements.rb @@ -59,12 +59,20 @@ class AboutControlStatements < EdgeCase::Koan def test_unless_statement result = :default_value - unless false + unless false # same as saying 'if !false', which evaluates as 'if true' result = :false_value end assert_equal __, result end + def test_unless_statement_evaluate_true + result = :default_value + unless true # same as saying 'if !true', which evaluates as 'if false' + result = :true_value + end + assert_equal __, result + end + def test_unless_statement_modifier result = :default_value result = :false_value unless false diff --git a/koans/about_iteration.rb b/koans/about_iteration.rb index b48c278..823128f 100644 --- a/koans/about_iteration.rb +++ b/koans/about_iteration.rb @@ -1,9 +1,16 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutIteration < EdgeCase::Koan + in_ruby_version("1.8") do + def test_each_is_a_method_on_arrays + assert_equal __, [].methods.include?("each") + end + end - def test_each_is_a_method_on_arrays - assert_equal __, [].methods.include?(:each) + in_ruby_version("1.9") do + def test_each_is_a_method_on_arrays + assert_equal __, [].methods.include?(:each) + end end def test_iterating_with_each diff --git a/koans/about_methods.rb b/koans/about_methods.rb index a4df4b8..5fd7725 100644 --- a/koans/about_methods.rb +++ b/koans/about_methods.rb @@ -62,6 +62,7 @@ class AboutMethods < EdgeCase::Koan end def test_calling_with_variable_arguments + assert_equal __, method_with_var_args.class assert_equal __, method_with_var_args assert_equal __, method_with_var_args(:one) assert_equal __, method_with_var_args(:one, :two) diff --git a/koans/about_regular_expressions.rb b/koans/about_regular_expressions.rb index 8344911..790bea3 100644 --- a/koans/about_regular_expressions.rb +++ b/koans/about_regular_expressions.rb @@ -84,6 +84,8 @@ class AboutRegularExpressions < EdgeCase::Koan def test_shortcut_character_classes_are_negated_with_capitals assert_equal __, "the number is 42"[/\D+/] assert_equal __, "space: \t\n"[/\S+/] + # ... a programmer would most likely do + assert_equal __, "variable_1 = 42"[/[^a-zA-Z0-9_]+/] assert_equal __, "variable_1 = 42"[/\W+/] end