Forum: Ruby Overloading math operations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7010c2a9fa9ebf326c7c858cd656926b?d=identicon&s=25 Frank Hirsch (0ffh)
on 2006-05-06 07:56
Hija,

been makin a little "Vector" class by extending Array.
Now I wanna add Vector support to the native numeric
data types in ruby. Means: Not only Vector+Numeric
but also Numeric+Vector should call my + function.

But I have a syntax prolem.. :-(

Example (not working!):

class Fixnum
  alias old+ + # here i have the syntax problem
  def +(other)
    if (other.class<=Vector)
      other+self
    else
      self.old+(other)
    end
  end
end

Someone please help poor ruby nooby! :-)))

Regards, 0ffh
3bef3fc4d0cbcf58f3d66c106e2fd16f?d=identicon&s=25 Mark Van Holstyn (Guest)
on 2006-05-06 08:14
(Received via mailing list)
Use this alias line...

alias :old_plus :+

both of the arguments to alias need to be symbols. also, "old+" wont be
a
happy method name.

Mark
7010c2a9fa9ebf326c7c858cd656926b?d=identicon&s=25 Frank Hirsch (0ffh)
on 2006-05-06 08:21
Mark Van Holstyn wrote:

> alias :old_plus :+
> both of the arguments to alias need to be symbols.
> also, "old+" wont be a happy method name.

Thanks alot!

Actually I have already tried "alias :old+ :+",
which gave a syntax error as well, but I didn't
realise it was yet another one... ;-)

Regards, 0ffh
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2006-05-06 08:44
(Received via mailing list)
2006/5/6, Frank Hirsch <0ffh@frankhirsch.net>:
> realise it was yet another one... ;-)
If you're not doing it for the fun of it: there are already vector and
matrix classes for Ruby plus libraries for manipulating them like
narray (see the RAA).

Kind regards

robert
7010c2a9fa9ebf326c7c858cd656926b?d=identicon&s=25 Frank Hirsch (0ffh)
on 2006-05-06 08:58
Robert Klemme wrote:
> If you're not doing it for the fun of it: there are already vector and
> matrix classes for Ruby plus libraries for manipulating them like
> narray (see the RAA).

I have seen and downloaded narray.

I don't use it because it is usually more hassle to
get stuff like that running and learn how to use it
and then find out that it is not quite what you've
been looking for after all than just DIY...

I am sitting here in a Hotel room with a newbought,
virgin Windoze notebook. I don't even want to try
to estimate how long it will take me to get the
compiler, utilities and whatnot up and running to
even _start_ to compile narray.
But if I can get no-hassle installable binaries
somewhere, I'll be happy to give it a chance.

Regards, Frank
Fc761ccaf6c0d7d977e2959f9bfebd06?d=identicon&s=25 Eli Bendersky (Guest)
on 2006-05-06 09:06
Frank Hirsch wrote:

> I am sitting here in a Hotel room with a newbought,
> virgin Windoze notebook. I don't even want to try
> to estimate how long it will take me to get the
> compiler, utilities and whatnot up and running to
> even _start_ to compile narray.
> But if I can get no-hassle installable binaries
> somewhere, I'll be happy to give it a chance.
>
> Regards, Frank

Ah... the reason that made my avoid so many Perl modules in my time... I
guess it's the same for Ruby. Perhaps it should be made a custom that
every extension library has a pure-Ruby version. This is useful for
prototyping - if one sees that the library fits his needs, he can later
put in the effort to actually compile and bind the extension to his
Ruby.

Perhaps a parallel for ActiveState's PPM (pre compiled modules) would be
nice. Unfortunately, Ruby still has no ActiveState version. Anyone knows
about plans to make it ?
7010c2a9fa9ebf326c7c858cd656926b?d=identicon&s=25 Frank Hirsch (0ffh)
on 2006-05-06 09:28
Eli Bendersky wrote:
> Perhaps a parallel for ActiveState's PPM (pre compiled modules) would be
> nice. Unfortunately, Ruby still has no ActiveState version. Anyone knows
> about plans to make it ?

No idea, but it makes for a very attractive idea!

Reagrds, 0ffh
This topic is locked and can not be replied to.