J
Joe Van Dyk
Can someone help me make this code not suck?
require 'test/unit'
# EWWWWWWW
def process_string str
result =3D Hash.new
str.to_a.each do |line|
line.scan(/important ([a-zA-Z0-9]+): /) do |key|
result[key.first] =3D line
end
end
result
end
class TestThis < Test::Unit::TestCase
def example_string
<<-END
# comments
important key1: some value's here
important key2: some value's here
important key3: some value's here
important key4: some value's here
other stuff we don't care about
END
end
def test_process_string
result =3D process_string example_string
assert 4, result.size
assert result.has_key?("key1")
assert result.has_key?("key2")
assert result.has_key?("key3")
assert result.has_key?("key4")
end
end
require 'test/unit'
# EWWWWWWW
def process_string str
result =3D Hash.new
str.to_a.each do |line|
line.scan(/important ([a-zA-Z0-9]+): /) do |key|
result[key.first] =3D line
end
end
result
end
class TestThis < Test::Unit::TestCase
def example_string
<<-END
# comments
important key1: some value's here
important key2: some value's here
important key3: some value's here
important key4: some value's here
other stuff we don't care about
END
end
def test_process_string
result =3D process_string example_string
assert 4, result.size
assert result.has_key?("key1")
assert result.has_key?("key2")
assert result.has_key?("key3")
assert result.has_key?("key4")
end
end