Daniel Bush wrote:
On 16/09/06, O Plameras <[EMAIL PROTECTED]> wrote:
...
> First, an 'operator' is a symbol that represents an action on one or
> more operands.
> When the behavior of this action changes(overloads) the operator is
> really a method.
> When the behavior is 'fixed' the operator is not a method.
...
Sorry, this should be,
http://phrogz.net/ProgrammingRuby/language.html#table_18.4
Thanks that was helpful.
I can see it has quite a few "non-method" operators. The ones that
are methods are completely methods with no restrictions. I was
angling towards operators on "primitives" or something like that ie in
C. There are different levels here.
Anyway, back to the arithmetic thing:
[pan: pan 1018]$ cat a_bit_stupid.rb
class Time
def plus *nums
nums.inject(self) {|sum,num| sum+num}
end
end
class Fixnum
def seconds
self
end
def minutes
self*60
end
def hours
self*3600
end
end
-----
[pan: pan 1001]$ irb
irb(main):001:0> require 'a_bit_stupid.rb'
=> true
irb(main):002:0> t=Time.now
=> Sat Sep 16 12:21:57 EST 2006
irb(main):003:0> t.plus 4.hours , 3.minutes , 2.seconds
=> Sat Sep 16 16:24:59 EST 2006
irb(main):004:0>
Awesome!!!! .... maybe.
Totally agree, without the '.... maybe'.
O Plameras
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders