News for hackers. Stuff that matters.
Re:Rails is not written in Ruby by dragonwriter on Saturday February 05, 2022 @05:06AM (#30219667)
> Those square parentheses are unfortunate because traditionally they are used to index arrays.

They’ve been among the methods for invoking procs since at least Ruby 1.8 (2003); there are several – all of these are equivalent.

  f[x]
  f.(x)
  f.call(x)
  f.yield(x)
> I’d like to write one of:

  2.g.f
  g(2).f
  (g >> f)(2)
  (f << g)(2)
Ruby is a pure OOP language, and “.” is the syntax for method invocation. So its really not available as a composition operator. So the first two don’t work for that reason. Further extending Ruby’s syntax to make unmodified parens both invoke methods and serve as syntax sugar for .call() on objects would probably be problematic (that’s why “.()” was adopted.)

> There is a ton of new syntax added to Ruby in the last years

None of the stuff related to this except the composition operators is added recently. And those aren’t really syntax, just normal operator methods added to the Proc class.

There are no comments on this comment yet.