mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Updated koans with changed from src.
This commit is contained in:
@@ -43,6 +43,28 @@ class Object
|
|||||||
end
|
end
|
||||||
|
|
||||||
module EdgeCase
|
module EdgeCase
|
||||||
|
|
||||||
|
module Color
|
||||||
|
#shamelessly stolen (and modified) from redgreen
|
||||||
|
COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36 }
|
||||||
|
|
||||||
|
COLORS.each do |color, value|
|
||||||
|
class_eval "def self.#{color}(string); colorize(string, #{value}); end"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.colorize(string, color_value)
|
||||||
|
if ENV['NO_COLOR']
|
||||||
|
string
|
||||||
|
else
|
||||||
|
color(color_value) + string + color(COLORS[:clear])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.color(color_value)
|
||||||
|
"\e[#{color_value}m"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class Sensei
|
class Sensei
|
||||||
attr_reader :failure, :failed_test
|
attr_reader :failure, :failed_test
|
||||||
|
|
||||||
@@ -67,9 +89,9 @@ module EdgeCase
|
|||||||
def accumulate(test)
|
def accumulate(test)
|
||||||
if test.passed?
|
if test.passed?
|
||||||
@pass_count += 1
|
@pass_count += 1
|
||||||
puts " #{test.name} has expanded your awareness."
|
puts Color.green(" #{test.name} has expanded your awareness.")
|
||||||
else
|
else
|
||||||
puts " #{test.name} has damaged your karma."
|
puts Color.red(" #{test.name} has damaged your karma.")
|
||||||
@failed_test = test
|
@failed_test = test
|
||||||
@failure = test.failure
|
@failure = test.failure
|
||||||
throw :edgecase_exit
|
throw :edgecase_exit
|
||||||
@@ -87,18 +109,19 @@ module EdgeCase
|
|||||||
def report
|
def report
|
||||||
if failed?
|
if failed?
|
||||||
puts
|
puts
|
||||||
puts "You have not yet reached enlightenment ..."
|
puts Color.green("You have not yet reached enlightenment ...")
|
||||||
puts failure.message
|
puts Color.red(failure.message)
|
||||||
puts
|
puts
|
||||||
puts "Please meditate on the following code:"
|
puts Color.green("Please meditate on the following code:")
|
||||||
if assert_failed?
|
if assert_failed?
|
||||||
puts find_interesting_lines(failure.backtrace)
|
#puts find_interesting_lines(failure.backtrace)
|
||||||
|
puts find_interesting_lines(failure.backtrace).collect {|l| Color.red(l) }
|
||||||
else
|
else
|
||||||
puts failure.backtrace
|
puts Color.red(failure.backtrace)
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
say_something_zenlike
|
puts Color.green(say_something_zenlike)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_interesting_lines(backtrace)
|
def find_interesting_lines(backtrace)
|
||||||
@@ -112,23 +135,24 @@ module EdgeCase
|
|||||||
def say_something_zenlike
|
def say_something_zenlike
|
||||||
puts
|
puts
|
||||||
if !failed?
|
if !failed?
|
||||||
puts "Mountains are again merely mountains"
|
zen_statement = "Mountains are again merely mountains"
|
||||||
else
|
else
|
||||||
case (@pass_count % 10)
|
zen_statement = case (@pass_count % 10)
|
||||||
when 0
|
when 0
|
||||||
puts "mountains are merely mountains"
|
"mountains are merely mountains"
|
||||||
when 1, 2
|
when 1, 2
|
||||||
puts "learn the rules so you know how to break them properly"
|
"learn the rules so you know how to break them properly"
|
||||||
when 3, 4
|
when 3, 4
|
||||||
puts "remember that silence is sometimes the best answer"
|
"remember that silence is sometimes the best answer"
|
||||||
when 5, 6
|
when 5, 6
|
||||||
puts "sleep is the best meditation"
|
"sleep is the best meditation"
|
||||||
when 7, 8
|
when 7, 8
|
||||||
puts "when you lose, don't lose the lesson"
|
"when you lose, don't lose the lesson"
|
||||||
else
|
else
|
||||||
puts "things are not what they appear to be: nor are they otherwise"
|
"things are not what they appear to be: nor are they otherwise"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
zen_statement
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -168,7 +192,7 @@ module EdgeCase
|
|||||||
|
|
||||||
def run_tests(accumulator)
|
def run_tests(accumulator)
|
||||||
puts
|
puts
|
||||||
puts "Thinking #{self}"
|
puts Color.green("Thinking #{self}")
|
||||||
testmethods.each do |m|
|
testmethods.each do |m|
|
||||||
self.run_test(m, accumulator) if Koan.test_pattern =~ m.to_s
|
self.run_test(m, accumulator) if Koan.test_pattern =~ m.to_s
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user