avatar

An hero

coder by day, an hero by night

gotcha: ruby []=

Another wat moment with:

1
2
3
4
5
class Bam
  def []=(key, value)
    "bam"
  end
end
1
2
3
irb> # I'm expecting "bam" to be the return value
irb> Bam.new[:ham] = :bacon
# => :bacon
1
2
3
irb> # But this works as expected
irb> Bam.new.public_send(:[]=, :ham, :bacon)
# => "bam"