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

  • Thread starter Daniel Bovensiepen [bovi]
  • Start date
D

Daniel Bovensiepen [bovi]

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:in `new'
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
 
J

Joel VanderWerf

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Bug with Ruby/Tk encoding (ruby-1.9.1-rc1) 6
Where is the extar end keyword. 2
tk fails to work with TkVariable 1
Ruby/Tk 10
Ruby TK 2
RemoteTkIp support on Ruby/Tk 0
Help with code 0
Tk and Tile with Tk8.5 9

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top