7stud -- wrote:
> Ruby gives you a choice with some methods, like +() and =(), to use a 
> special syntax.

Just to be clear, =() can't be used as a method name, you must add a 
name ( x=() )
a.b = 2 calls the method "b=" of the object a : a.send("b=", 2)
a = 2 gives the name "a" to the object "2".

"a = 2" can't affect the old object names "a" (ruby != C++)



Sarah Allen wrote:
> 4 div 2

"4 div 2" means "4(div(2))"

note: The operators can't be used as variable names, so there is no risk 
"var + 3" means "var(+, 3)", that is no valid ruby.


Just for fun:

I think it can be possible to create a dsl to do what you want:
- method_missing create objects (I will call them Flux)
  that keep its name and argument
- if the name of the method is also the name of an existing variable,
  and the argument is a Flux,
  then it call the stored method with variable and the stored argument
So "var div 2" means Flux.new(:div, 2).call(var) which means 
"var.send(:div,2)"
But there are many limitations (for instance, "4" is not a valid method 
name)

--
Etienne Vallette d'Osia
-- 
Posted via http://www.ruby-forum.com/.