Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
### Helper code

class Context

  attr_reader :content

  def initialize(content)
    @content = content
  end

  def replace(old_string, new_string)
    @content.gsub!(old_string, new_string)
  end

end

def magic(content, &block)
  Context.new(content).instance_eval(&block)
end

### Actual code

stuff = 'blah blaaah blah'
magic(stuff) do
  replace 'blaaah', 'moo'
  content.upcase!
end

puts stuff.inspect