Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
p.159 offeces;before refactoring.
  • Loading branch information
kono committed May 30, 2010
1 parent 4b21f32 commit 6fa4b1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions chapter6/Replace_Loop_with_Collection_Closure_Method.rb
@@ -1,8 +1,9 @@
class Employees
attr_reader :name
def initialize(name, ismanager)
attr_reader :name, :office
def initialize(name, ismanager, office)
@name = name
@manager = ismanager
@office = office
end

def manager?
Expand All @@ -18,3 +19,9 @@ def test_proc(employees)

managers = employees.select{|e| e.manager?}
end

def office_proc(employees)
offices = []
employees.each{|e| offices << e.office}
return offices
end
14 changes: 10 additions & 4 deletions chapter6/TC_Replace_Loop_with_Collection_Closure_Method.rb
Expand Up @@ -17,10 +17,10 @@ def assert(status,msg)

must "test_test_proc" do
employees = []
employees << Employees.new("Alan", true)
employees << Employees.new("Barbara", false)
employees << Employees.new("Charlie", false)
employees << Employees.new("Diana",true)
employees << Employees.new("Alan", true, "Japan")
employees << Employees.new("Barbara", false, "Japan")
employees << Employees.new("Charlie", false, "USA")
employees << Employees.new("Diana",true, "USA")

manager_name = []

Expand All @@ -32,5 +32,11 @@ def assert(status,msg)
assert_nil( manager_name.index("Barbara"))
assert_nil( manager_name.index("Charlie"))
assert_not_nil( manager_name.index("Diana"))

office_ar= office_proc(employees)
assert_not_nil(office_ar.index("Japan"))
assert_not_nil(office_ar.index("USA"))

end

end

0 comments on commit 6fa4b1a

Please sign in to comment.