Ruby/Tk core library desing question (TkCanvas#create)

For TkCanvas#create method, it returns "1" seems useless ...
( Does "1" means successful ? )

To fit in "Ruby" world, it would be better TkCanvas#create returns self.

So you can write something like:
TkCanvas.new.pack.create(TkcRectangle, 0, 0, 5, 5).create(TkcOvale,
50, 50, 70, 70)

Currently, you cannot, the TkCanvas#create returns Fixnum 1.

Thank you.

Or maybe the TkCanvas#create return the item created. Like:
line = TkCanvas.new.pack.create(TkcLine, 0, 0, 100, 100)
so the line is TkcLine instance object.

But I still prefer TkCanvas#create returns self.
( so I can "chain" the TkCanvas methods )

Anyway, currentely returns 1 just seems useless to me.

Thank you.

···

On 8/8/05, David Tran <email55555@gmail.com> wrote:

For TkCanvas#create method, it returns "1" seems useless ...
( Does "1" means successful ? )

To fit in "Ruby" world, it would be better TkCanvas#create returns self.

So you can write something like:
TkCanvas.new.pack.create(TkcRectangle, 0, 0, 5, 5).create(TkcOvale,
50, 50, 70, 70)

Currently, you cannot, the TkCanvas#create returns Fixnum 1.

Thank you.

Message-ID: <91b08b8a050808145333ff26be@mail.gmail.com>

For TkCanvas#create method, it returns "1" seems useless ...
( Does "1" means successful ? )

No. That is the identifier of the canvas item.
TkCanvas#create method is used when you don't want to create
a ruby object for a canvas item (for example, you worry about
memory costs for many items).
And then, to configure the item, you have to use the identifier
(if you don't give canvas tags to the item).
You shouldn't assume that the return value is a number.

···

From: David Tran <email55555@gmail.com>
Subject: Ruby/Tk core library desing question (TkCanvas#create)
Date: Tue, 9 Aug 2005 06:53:28 +0900
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

No. That is the identifier of the canvas item.
TkCanvas#create method is used when you don't want to create
a ruby object for a canvas item (for example, you worry about
memory costs for many items).
And then, to configure the item, you have to use the identifier
(if you don't give canvas tags to the item).
You shouldn't assume that the return value is a number.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

I missunderstood the return value.

require 'tk'
c = TkCanvas.new.pack
r = c.create(TkcRectangle, 10, 10, 50, 50)
puts "r = #{r}; type = #{r.class}"
c.itemconfigure(r, :fill=>:red)
Tk.mainloop

Got it now, even the r is Fixnum class, it is item identifier.
So, later we can use it on itemconfigure to modify the item.

Thank you.