Does this conflict with some kind of basic rule in the grammer?
Could it be an RCR, or is just wrong-headed?
I want to assign into an object, but I want to take a proc as an arg, so
that the assignment can be "paramaterized" in some sense, like;
# Usually:
card.email = "user@example.com"
# Sometimes:
card.email = "user@example.com" do |e|
聽聽e.type = 'preferred'
聽聽e.protocol = 'uucp'
聽聽e.location = 'work'
end
It doesn't seem to be allowed, I did a quick test:
聽聽class Foo
聽聽聽聽def bar=(arg)
聽聽聽聽聽聽yield "got: #{arg}"
聽聽聽聽end
聽聽end
聽聽f = Foo.new
聽聽# Syntax error
聽聽f.bar = "hi do end" do |s|
聽聽聽聽puts "do/end #{s}"
聽聽end
I also tried to do a = method with two args, the second optional.
It prints nothing, but runs, which makes me wonder what its doing!
class Foo
聽聽def bar=(arg, blk = nil)
聽聽聽聽if blk
聽聽聽聽聽聽blk.call("got: #{arg}")
聽聽聽聽end
聽聽end
end
f = Foo.new
f.bar = "hi bare"
f.bar = " hi do end", proc { |s| puts "do/end #{s}" }
Cheers,
Sam