mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-21 01:03:20 -04:00
UPdated koans to match latest source.
This commit is contained in:
@@ -7,6 +7,6 @@ require 'rake/testtask'
|
|||||||
task :default => :test
|
task :default => :test
|
||||||
|
|
||||||
task :test do
|
task :test do
|
||||||
ruby 'path_to_enlightenment.rb'
|
ruby '-I.', 'path_to_enlightenment.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutArrayAssignment < EdgeCase::Koan
|
class AboutArrayAssignment < EdgeCase::Koan
|
||||||
def test_non_parallel_assignment
|
def test_non_parallel_assignment
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutArrays < EdgeCase::Koan
|
class AboutArrays < EdgeCase::Koan
|
||||||
def test_creating_arrays
|
def test_creating_arrays
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# -*- ruby -*-
|
# -*- ruby -*-
|
||||||
|
|
||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutAsserts < EdgeCase::Koan
|
class AboutAsserts < EdgeCase::Koan
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutBlocks < EdgeCase::Koan
|
class AboutBlocks < EdgeCase::Koan
|
||||||
def method_with_block
|
def method_with_block
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutClassMethods < EdgeCase::Koan
|
class AboutClassMethods < EdgeCase::Koan
|
||||||
class Dog
|
class Dog
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutClasses < EdgeCase::Koan
|
class AboutClasses < EdgeCase::Koan
|
||||||
class Dog
|
class Dog
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
C = "top level"
|
C = "top level"
|
||||||
|
|
||||||
@@ -83,5 +83,5 @@ class AboutConstants < EdgeCase::Koan
|
|||||||
|
|
||||||
# QUESTION: Now Which has precedence: The constant in the lexical
|
# QUESTION: Now Which has precedence: The constant in the lexical
|
||||||
# scope, or the constant from the inheritance heirarachy? Why is it
|
# scope, or the constant from the inheritance heirarachy? Why is it
|
||||||
# different?
|
# different than the previous answer?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutControlStatements < EdgeCase::Koan
|
class AboutControlStatements < EdgeCase::Koan
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class DiceSet
|
class DiceSet
|
||||||
attr_reader :values
|
attr_reader :values
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutExceptions < EdgeCase::Koan
|
class AboutExceptions < EdgeCase::Koan
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutHashes < EdgeCase::Koan
|
class AboutHashes < EdgeCase::Koan
|
||||||
def test_creating_hashes
|
def test_creating_hashes
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutInheritance < EdgeCase::Koan
|
class AboutInheritance < EdgeCase::Koan
|
||||||
class Dog
|
class Dog
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutIteration < EdgeCase::Koan
|
class AboutIteration < EdgeCase::Koan
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutMessagePassing < EdgeCase::Koan
|
class AboutMessagePassing < EdgeCase::Koan
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
def my_global_method(a,b)
|
def my_global_method(a,b)
|
||||||
a + b
|
a + b
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutModules < EdgeCase::Koan
|
class AboutModules < EdgeCase::Koan
|
||||||
module Nameable
|
module Nameable
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutNil < EdgeCase::Koan
|
class AboutNil < EdgeCase::Koan
|
||||||
def test_nil_is_an_object
|
def test_nil_is_an_object
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutOpenClasses < EdgeCase::Koan
|
class AboutOpenClasses < EdgeCase::Koan
|
||||||
class Dog
|
class Dog
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
# Project: Create a Proxy Class
|
# Project: Create a Proxy Class
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutUsingBlocks < EdgeCase::Koan
|
class AboutUsingBlocks < EdgeCase::Koan
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutScope < EdgeCase::Koan
|
class AboutScope < EdgeCase::Koan
|
||||||
module Jims
|
module Jims
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
# Greed is a dice game where you roll up to five dice to accumulate
|
# Greed is a dice game where you roll up to five dice to accumulate
|
||||||
# points. The following "score" function will be used calculate the
|
# points. The following "score" function will be used calculate the
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutStrings < EdgeCase::Koan
|
class AboutStrings < EdgeCase::Koan
|
||||||
def test_double_quoted_strings_are_strings
|
def test_double_quoted_strings_are_strings
|
||||||
@@ -146,12 +146,21 @@ EOS
|
|||||||
# Surprised?
|
# Surprised?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_single_characters_are_represented_by_integers
|
in_ruby_version("1.8") do
|
||||||
|
def test_in_ruby_1_8_single_characters_are_represented_by_integers
|
||||||
assert_equal __, ?a
|
assert_equal __, ?a
|
||||||
assert_equal __, ?a == 97
|
assert_equal __, ?a == 97
|
||||||
|
|
||||||
assert_equal __, ?b == (?a + 1)
|
assert_equal __, ?b == (?a + 1)
|
||||||
end
|
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
|
def test_strings_can_be_split
|
||||||
string = "Sausage Egg Cheese"
|
string = "Sausage Egg Cheese"
|
||||||
@@ -166,7 +175,7 @@ EOS
|
|||||||
|
|
||||||
# NOTE: Patterns are formed from Regular Expressions. Ruby has a
|
# NOTE: Patterns are formed from Regular Expressions. Ruby has a
|
||||||
# very powerful Regular Expression library. Unfortunately, time
|
# 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
|
end
|
||||||
|
|
||||||
def test_strings_can_be_joined
|
def test_strings_can_be_joined
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
# You need to write the triangle method in the file 'triangle.rb'
|
# You need to write the triangle method in the file 'triangle.rb'
|
||||||
require 'triangle.rb'
|
require 'triangle.rb'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
# You need to write the triangle method in the file 'triangle.rb'
|
# You need to write the triangle method in the file 'triangle.rb'
|
||||||
require 'triangle.rb'
|
require 'triangle.rb'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|
||||||
class AboutTrueAndFalse < EdgeCase::Koan
|
class AboutTrueAndFalse < EdgeCase::Koan
|
||||||
def truth_value(condition)
|
def truth_value(condition)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
require 'edgecase'
|
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||||
|
|||||||
@@ -6,12 +6,24 @@ require 'test/unit/assertions'
|
|||||||
class FillMeInError < StandardError
|
class FillMeInError < StandardError
|
||||||
end
|
end
|
||||||
|
|
||||||
def __(value="FILL ME IN")
|
def in_ruby_version(version)
|
||||||
value
|
yield if RUBY_VERSION =~ /^#{version}/
|
||||||
end
|
end
|
||||||
|
|
||||||
def _n_(value=999999)
|
def __(value="FILL ME IN", value19=:mu)
|
||||||
|
if RUBY_VERSION < "1.9"
|
||||||
value
|
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
|
end
|
||||||
|
|
||||||
def ___(value=FillMeInError)
|
def ___(value=FillMeInError)
|
||||||
|
|||||||
Reference in New Issue
Block a user