2011/5/7 Stefan Salewski <mail / ssalewski.de>:
>
> Of course this is a way to solve the problem. It may look not very
> natural, that we have to tell the fish the parameters of its tank, when
> we ask the fish about its mood:
>
>>mood =3D =A0fish.tell_mood({:temp =3D> t.temp, :food =3D> t.food_type})
>
> But OK, this is the way to do it. Now I know that I have not missed
> something.

A little late to this, but isn't this a good case for the Observer pattern?
So the fish are always "aware" of the tank environment? Very simply:

-----------------------------
require 'observer'

class Tank
  include Observable

  def temperature
    @temperature
  end

  def temperature=3D(temperature)
    @temperature =3D temperature
    changed
    notify_observers(temperature)
  end

end

class Fish

  attr_accessor :tank_temperature

  def initialize(tank)
    @tank_temperature =3D tank.temperature
    tank.add_observer(self)
  end

  def update(temperature)
    puts "temperature changed to #{temperature}"
    @tank_temperature =3D temperature
  end

end
-----------------------------
And exercise with:
-----------------------------
require 'tank'
require 'fish'

tank =3D Tank.new
tank.temperature=3D 100
fish =3D Fish.new(tank)
puts "fish.tank_temperature: #{fish.tank_temperature}"  # =3D> 100

tank.temperature=3D 102
puts "fish.tank_temperature: #{fish.tank_temperature}" # =3D> 102
-----------------------------

FWIW,
--=20
Hassan Schroeder ------------------------ hassan.schroeder / gmail.com
twitter: @hassan