--r5Pyd7+fXNt84Ff3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Thomas Sondergaard (thomas / FirstNameGoesHereSondergaard.com) wrote:

> How do you feel about this feature. Would it be a big loss if ruby didn't
> support it?

This feature makes porting or refactoring code in Ruby a dream.

Take this code, for example:

class Module
  private
  def move_class_methods (cls, *attrs)
    attrs.each {|attr|
      module_eval(<<-EOS)
        def self.#{attr}(*args)
          $stderr.puts "WARNING: #{cls}.#{attr} called from " + caller[0]
          #{cls}.#{attr}(*args)
        end
      EOS
    }
  end
end

It allows you to easily redefine/move class methods from one class
to another:

class OldLocation
  move_class_methods(NewLocation, :foo)

  def bar
    return self.foo(1, 2)
  end
end

class NewLocation
  def self.foo(x, y)
    return x * y + y ** 2 - 3
  end
end

You could write similar code to aid in refactoring instance methods.

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04


--r5Pyd7+fXNt84Ff3
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/dhD3MypVHHlsnwQRAnVBAJ9E8kgbPLe8oYPaCphjLWsIpGfTbACgz9nc
fxIbRm++nDRAlh6nWIq5OJYPQV
-----END PGP SIGNATURE-----

--r5Pyd7+fXNt84Ff3--