task :default => :test
task :test do
- ruby 'path_to_enlightenment.rb'
+ ruby '-I.', 'path_to_enlightenment.rb'
end
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutArrayAssignment < EdgeCase::Koan
def test_non_parallel_assignment
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutArrays < EdgeCase::Koan
def test_creating_arrays
#!/usr/bin/env ruby
# -*- ruby -*-
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutAsserts < EdgeCase::Koan
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutBlocks < EdgeCase::Koan
def method_with_block
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutClassMethods < EdgeCase::Koan
class Dog
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutClasses < EdgeCase::Koan
class Dog
fido = Dog2.new
fido.set_name("Fido")
- assert_equal __, fido.instance_variable_get("@name")
+ assert_equal __, fido.instance_variable_get("@name")
end
def test_you_can_rip_the_value_out_using_instance_eval
assert_equal __, fido.name
end
-
+
# ------------------------------------------------------------------
class Dog5
# THINK ABOUT IT:
# Why is this so?
end
-
+
def test_different_objects_have_difference_instance_variables
fido = Dog6.new("Fido")
rover = Dog6.new("Rover")
assert_equal __, "STRING".to_s
assert_equal __, "STRING".inspect
end
-
+
end
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
C = "top level"
end
# ------------------------------------------------------------------
-
+
class Animal
LEGS = 4
def legs_in_animal
end
end
end
-
+
def test_nested_classes_inherit_constants_from_enclosing_classes
- assert_equal __, Animal::NestedAnimal.new.legs_in_nested_animal
+ assert_equal __, Animal::NestedAnimal.new.legs_in_nested_animal
end
# ------------------------------------------------------------------
-
+
class Reptile < Animal
def legs_in_reptile
LEGS
end
end
-
+
def test_subclasses_inherit_constants_from_parent_classes
assert_equal __, Reptile.new.legs_in_reptile
end
-
+
# ------------------------------------------------------------------
-
+
class MyAnimals
LEGS = 2
end
end
end
-
+
def test_who_wins_with_both_nested_and_inherited_constants
assert_equal __, MyAnimals::Bird.new.legs_in_bird
end
-
+
# QUESTION: Which has precedence: The constant in the lexical scope,
# or the constant from the inheritance heirarachy?
-
+
# ------------------------------------------------------------------
-
+
class MyAnimals::Oyster < Animal
def legs_in_oyster
LEGS
# QUESTION: Now Which has precedence: The constant in the lexical
# scope, or the constant from the inheritance heirarachy? Why is it
- # different?
+ # different than the previous answer?
end
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutControlStatements < EdgeCase::Koan
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class DiceSet
attr_reader :values
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutExceptions < EdgeCase::Koan
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutHashes < EdgeCase::Koan
def test_creating_hashes
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutInheritance < EdgeCase::Koan
class Dog
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutIteration < EdgeCase::Koan
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutMessagePassing < EdgeCase::Koan
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
def my_global_method(a,b)
a + b
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutModules < EdgeCase::Koan
module Nameable
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutNil < EdgeCase::Koan
def test_nil_is_an_object
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutOpenClasses < EdgeCase::Koan
class Dog
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Project: Create a Proxy Class
#
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutUsingBlocks < EdgeCase::Koan
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutScope < EdgeCase::Koan
module Jims
rover = Joes::Dog.new
assert_equal __, fido.identify
assert_equal __, rover.identify
-
+
assert_not_equal fido.class, rover.class
assert_not_equal Jims::Dog, Joes::Dog
end
def test_bare_bones_class_names_assume_the_current_scope
assert_equal __, AboutScope::String == String
end
-
+
def test_nested_string_is_not_the_same_as_the_system_string
assert_equal __, String == "HI".class
end
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used calculate the
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutStrings < EdgeCase::Koan
def test_double_quoted_strings_are_strings
# Surprised?
end
- def test_single_characters_are_represented_by_integers
- assert_equal __, ?a
- assert_equal __, ?a == 97
+ in_ruby_version("1.8") do
+ def test_in_ruby_1_8_single_characters_are_represented_by_integers
+ assert_equal __, ?a
+ assert_equal __, ?a == 97
- assert_equal __, ?b == (?a + 1)
+ assert_equal __, ?b == (?a + 1)
+ end
+ end
+
+ in_ruby_version("1.9") do
+ def test_in_ruby_1_8_single_characters_are_represented_by_strings
+ assert_equal __, ?a
+ assert_equal __, ?a == 97
+ end
end
def test_strings_can_be_split
# NOTE: Patterns are formed from Regular Expressions. Ruby has a
# very powerful Regular Expression library. Unfortunately, time
- # does not permit us to explore it in detail in Ruby 101.
+ # does not permit us to explore it in detail now.
end
def test_strings_can_be_joined
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# You need to write the triangle method in the file 'triangle.rb'
require 'triangle.rb'
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# You need to write the triangle method in the file 'triangle.rb'
require 'triangle.rb'
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutTrueAndFalse < EdgeCase::Koan
def truth_value(condition)
-require 'edgecase'
+require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class FillMeInError < StandardError
end
-def __(value="FILL ME IN")
- value
+def in_ruby_version(version)
+ yield if RUBY_VERSION =~ /^#{version}/
end
-def _n_(value=999999)
- value
+def __(value="FILL ME IN", value19=:mu)
+ if RUBY_VERSION < "1.9"
+ value
+ else
+ (value19 == :mu) ? value : value19
+ end
+end
+
+def _n_(value=999999, value19=:mu)
+ if RUBY_VERSION < "1.9"
+ value
+ else
+ (value19 == :mu) ? value : value19
+ end
end
def ___(value=FillMeInError)
end
end
end
- end
+ end
class Koan
include Test::Unit::Assertions
load(arg)
else
fail "Unknown command line argument '#{arg}'"
- end
+ end
end
end
end