Current progress

This commit is contained in:
Adam Mohammed
2023-03-20 17:10:07 -04:00
parent 89cba6e600
commit 818436f4b4
42 changed files with 3907 additions and 0 deletions

63
koans/about_modules.rb Normal file
View File

@@ -0,0 +1,63 @@
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutModules < Neo::Koan
module Nameable
def set_name(new_name)
@name = new_name
end
def here
:in_module
end
end
def test_cant_instantiate_modules
assert_raise(___) do
Nameable.new
end
end
# ------------------------------------------------------------------
class Dog
include Nameable
attr_reader :name
def initialize
@name = "Fido"
end
def bark
"WOOF"
end
def here
:in_object
end
end
def test_normal_methods_are_available_in_the_object
fido = Dog.new
assert_equal __, fido.bark
end
def test_module_methods_are_also_available_in_the_object
fido = Dog.new
assert_nothing_raised do
fido.set_name("Rover")
end
end
def test_module_methods_can_affect_instance_variables_in_the_object
fido = Dog.new
assert_equal __, fido.name
fido.set_name("Rover")
assert_equal __, fido.name
end
def test_classes_can_override_module_methods
fido = Dog.new
assert_equal __, fido.here
end
end