From 271dff23530ef0b2c007865c6286c5b97e9020a6 Mon Sep 17 00:00:00 2001 From: Jim Weirich Date: Sun, 4 Dec 2011 00:57:08 -0500 Subject: [PATCH] Fixed :each VS "each" conflict in method list inclusion. --- src/about_iteration.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/about_iteration.rb b/src/about_iteration.rb index 324a116..2e35aa9 100644 --- a/src/about_iteration.rb +++ b/src/about_iteration.rb @@ -2,8 +2,29 @@ require File.expand_path(File.dirname(__FILE__) + '/edgecase') class AboutIteration < EdgeCase::Koan + # -- An Aside ------------------------------------------------------ + # Ruby 1.8 stores names as strings. Ruby 1.9 stores names as + # symbols. So we use a version dependent method "as_name" to convert + # to the right format in the koans. We will use "as_name" whenever + # comparing to lists of methods. + + in_ruby_version("1.8") do + def as_name(name) + name.to_s + end + end + + in_ruby_version("1.9") do + def as_name(name) + name.to_sym + end + end + + # Ok, now back to the Koans. + # ------------------------------------------------------------------- + def test_each_is_a_method_on_arrays - [].methods.include?("each") + assert_equal __(true), [].methods.include?(as_name(:each)) end def test_iterating_with_each -- 1.8.0.2