Benno wrote:
On Sat Sep 16, 2006 at 02:04:49 +1000, Daniel Bush wrote:
On 15/09/06, Benno <[EMAIL PROTECTED]> wrote:
...
The real codes,
#cat my_codes.rb
require 'date'
puts today = Date.today #=> prints 2006-09-15
puts tomorrow = today + 1 #=> prints 2006-09-16
puts yesterday = today - 1 #=> prints 2006-09-14
puts nextweek = today + 7 #=> prints 2006-09-22
Mmm, it is worth noting that two things are going on here.
1/ Operator overloading. That is + being used for date types.
2/ Automatic type conversion. Converting the integer 1 to a "day".
Does ruby have operators? What is an operator?
I thought that '+' is just a method.
I think you are just playing semantics here. Syntacticly '+' is an operator,
even in ruby. Whether that maps to a method at the end of the day or not.
(In python is maps to the __add__ method, although Python special cases
integer addition inside the interpreter -- not sure about ruby).
Yes, there are 'operators' in Ruby.
And there are operators that are methods.
So, the questions by the previous poster are legitimate
which I will attempt to answer in the following:
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.
Secondly, we all know that a 'method' is a function, procedure, or routine
and associated with 'class'. This is just to clarify the meaning of
method as I used it.
Complete examples of operators (both types):
http://phrogz.net/ProgrammingRuby/language.html
O Plameras
Disclaimer: When my opinions differ from yours
it does not mean you are wrong
and I am right.
When you make omissions
I do not take it to mean you do
not know what you have not
included.
_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders