I’m assuming it’s doing a little compile time checking, or lazily converting
the call to the correct type at runtime?
One important differentiation is local variable or not. If it is a
local variable, Ruby knows that there are no arguments and the
following must be method call on the object held in the variable. If
it is not a local variable a space indicates arguments while a missing
space before “[” indicates that we have a call of method #[]. Try
this:
def foo(i) printf(“Meth %p\n”, i) end
bar = lambda {|i| printf(“Block %p\n”, i)}
def baz; lambda {|i| printf(“BlockMeth %p\n”, i)} end
foo [1]
bar [2] #baz [3] #foo[4]
bar[5]
baz[6]
Commented lines fail:
3: wrong number of arguments (1 for 0) (ArgumentError)
4: wrong number of arguments (0 for 1) (ArgumentError)
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.