TCLTK didn't work with do ... end?

hi,

i have been played with tcltk and currently i used the button-widget
like the following:

TkButton.new(root) do
text 'i am a button’
pack do
padx 400
pady 400
side right
end
command proc {
puts ‘klick’
}
end

my question is:
why didn’t work the ‘command proc’ with a do … end?

i’ve been try this:

TkButton.new(root) do
text 'i am a button’
pack do
padx 400
pady 400
side right
end
command proc do
puts 'klick’
end
end

and then i get this:
tk.rb:23:in proc': tried to create Proc object without a block (ArgumentError) from tk.rb:23 from tk.rb:16:innew’
from tk.rb:16:in `new’
from tk.rb:16

why is ruby saying this?
i don’t like bracket and so i’am sooo unhappy about this snifff

gentoo
kernel 2.6.5
gcc 3.3.3
ruby 1.9.0
tk 8.4.6

bovi

<- i’am a german guy, so i didn’t write this language very well (-:
sorry for this

Daniel Bovensiepen [bovi] wrote:

command proc {
puts ‘klick’
}

why didn’t work the ‘command proc’ with a do … end?

command proc do
puts ‘klick’
end

It’s because of precedence. In the first case, the {…} is associated
with ‘proc’. In the second case, it is associated with ‘command’. This
may show it more clearly:

def foo(*args, &bl)
puts “In foo: got args == #{args.inspect}”
puts “In foo: got block == #{bl.inspect}”
end

def bar(*args, &bl)
puts “In bar: got args == #{args.inspect}”
puts “In bar: got block == #{bl.inspect}”
end

foo bar {}

foo bar do end

– output –
In bar: got args ==
In bar: got block == #Proc:0x00000000@-:11
In foo: got args == [nil]
In foo: got block == nil
In bar: got args ==
In bar: got block == nil
In foo: got args == [nil]
In foo: got block == #Proc:0x00000000@-:13

thanks a lot for this good explanation…