It is possible to define a method in ... = format like this:
class A
def f= x
puts x
end
end
A.new.f = 5
But is it possible to define a method in this format with arguments so that it can be used like the following?
A.new.f(a, b, c) = 5
Edit
You can do this with []=
class A
def []= x, y, z
puts x, y, z
end
end
A.new[1, 2] = 3
Is this an exceptional case?
is syntax error, so for sure not (this doesn’t make sense too 😉
[]is just sugar for .send(:[]=, …) which is just setter with fancy name.You can define setter with multiple arguments, but the only way to use it is by
A.new.send(:f=, "first", "second")because parser doesn’t allow syntax like A.new.foo = “first”, “second”.