1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class A
  def foo
    'A'
  end
end

class B < A
  def foo
    if rand() < 0.5
      'B'
    else
      super
    end
  end
end

puts A.new.foo # => A

10.times do
  puts B.new.foo  # => prints 'B' 50% of the time
end