Implement a fancier version of attr_accessor that includes validation. Complete the attr_validated code below so that the unit tests pass.
require 'test/unit'
class Dog
def self.attr_validated(method_name, &validation)
# Complete this method so that the unit tests pass
end
attr_validated :num_legs do |v|
v <= 4
end
end
class TestDog < Test::Unit::TestCase
def test_good_value
dog = Dog.new
dog.num_legs = 3
assert_equal 3, dog.num_legs
end
def test_nil_value
dog = Dog.new
assert_raises ArgumentError do
dog.num_legs = nil
end
end
def test_illegal_value
dog = Dog.new
assert_raises ArgumentError do
dog.num_legs = 5
end
end
end