Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Jim Weirich http://onestepback.org

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Kata Test Case

class TestStepOne
def test_unidirectional
jim = User.new("Jim")
admin = Role.new("Admin")
jim.add_role(admin)
user.add_user(jim)
assert_equals [admin], jim.roles
assert_equals [jim], admin.users
end
end

class TestStepTwo
def test_bidirectional_from_user
jim = User.new("Jim")
admin = Role.new("Admin")
jim.add(admin)
assert_equals [admin], jim.roles
assert_equals [jim], admin.users
end

def test_bidirectional_from_role
jim = User.new("Jim")
admin = Role.new("Admin")
admin.add(jim)
assert_equals [admin], jim.roles
assert_equals [jim], admin.users
end
end

Example of Detecting Subclasses

class A
def A.inherited(clazz)
puts "Hey, #{clazz} is subclassing me"
end
end

class B < A; end


Produces:

$ ruby x.rb
Hey, B is subclassing me
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS