I have a Builder class that lets you add to one of it's instance variables:
class Builder
def initialize
@lines = []
end
def lines
block_given? ? yield(self) : @lines
end
def add_line( text )
@lines << text
end
end
Now, how do I change this
my_builder = Builder.new
my_builder.lines { |b|
b.add_line "foo"
b.add_line "bar"
}
p my_builder.lines # => ["foo", "bar"]
Into this?
my_builder = Builder.new
my_builder.lines {
add_line "foo"
add_line "bar"
}
p my_builder.lines # => ["foo", "bar"]