[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:02094] Re: Array Gotchas

From: gotoken@... (GOTO Kentaro)
Date: 2000-03-23 02:34:42 UTC
List: ruby-talk #2094
Hi, 

In message "[ruby-talk:02091] Array Gotchas"
    on 00/03/22, "Dat Nguyen" <thucdat@hotmail.com> writes:
>While I was wondering why '+' was the concatenation and '-' was the 
>subtraction, I learned that Array indeed has the concat(other) method, but 
>not the substract(other) method and many other explicite spelling ones.
>
>There is already '+' for concatenation, why concat(other). When 
>concat(other) why not substract(other) also. And what about union(other), 
>etc.
>
>This is a sort of incompleteness and redundancy.

At first, `+' and `concat' is slightly different. 

  a, b = [1, 2, 3], [4, 5, 6]

  a + b;       p a #=> [1, 2, 3]
  a.concat b;  p a #=> [1, 2, 3, 4, 5, 6]
  
Second, `substract' does indeed not exist.  If you would strongly like
to add the method as built-in one, we would start discussion.  Or, you
can define as follows:

  class Array
    def substract(other)
      replace(self - other)
    end
  end

  a, b = [1, 2, 3, 4, 5, 6], [1, 3, 5]
  a - b;         p a #=> [1, 2, 3, 4, 5, 6]
  a.substract b; p a #=> [2, 4, 6]

Regards,

-- gotoken

In This Thread