Skip to content

Instantly share code, notes, and snippets.

@SolomonHD
Created March 2, 2015 14:20
Show Gist options
  • Save SolomonHD/ac37d02be55fa56687e0 to your computer and use it in GitHub Desktop.
Save SolomonHD/ac37d02be55fa56687e0 to your computer and use it in GitHub Desktop.
02MAR15 Quiz
require 'minitest/autorun'
require 'minitest/pride'
# Write a class which has an initialize method, a reader method, a private
# method, and a class method.
# WRITE YOUR CODE HERE.
class Goat
def initialize(name = "default")
@name = name
end
def name
return @name
end
def self.number_of_legs
return 4
end
def self.send(method)
self.method
end
private def hate_cats
return "I hate cats!"
end
end
class ClassesChallenge < MiniTest::Test
def test_class_exists
assert Goat
end
def test_initialize
assert Goat.new("Windsong")
end
def test_reader
amalthea = Goat.new("Amalthea")
assert_equal "Amalthea", amalthea.name
assert_raises(NoMethodError) do
amalthea.name = "Djali"
end
end
def test_private
billy = Goat.new("Billy Whiskers")
assert_raises(NoMethodError) do
billy.hate_cats
end
assert_equal "I hate cats!", billy.send(:hate_cats)
end
def test_class
assert_equal 4, Goat.number_of_legs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment