librelist archives

« back to archive

[green_shoes]:symbol vs .method

[green_shoes]:symbol vs .method

From:
Catsquotl
Date:
2011-03-04 @ 12:42
Hi,

Can someone please explain why i can write.
list_box :items =>@m, :choose =>"#{@m[1]}" do
some code here
end

but not.
@list = list_box :items =>@m
@list.choose("#{@m[1]}") do
some code here
end

I find i am rather clueless about this and it has me searching docs and 
experimenting for hours to find out the propper way to write the first 
example. i'd like to be able to store the first list box in a variable 
and call its change or choose method..

Eelco

Re: [shoes] [green_shoes]:symbol vs .method

From:
Elias Crespin
Date:
2011-03-04 @ 13:12
Hi Eelco,

This syntax is ruby's responsibility.

It is required because hashes are used to implement named parameters to call
the list_box initializer method. In the example you are calling the list_box
constructor or initializer method with parameters items and choose.

A start explanation for named parameters in ruby can be found here
http://ruby.about.com/od/advancedruby/qt/opthash.htm

You may also google "ruby named parameters" or "ruby hash method parameters"
(without the quotes)

Hope this helps.

Elias Crespin.


On Fri, Mar 4, 2011 at 1:42 PM, Catsquotl <catsquotl@gmail.com> wrote:

> Hi,
>
> Can someone please explain why i can write.
> list_box :items =>@m, :choose =>"#{@m[1]}" do
> some code here
> end
>
> but not.
> @list = list_box :items =>@m
> @list.choose("#{@m[1]}") do
> some code here
> end
>
> I find i am rather clueless about this and it has me searching docs and
> experimenting for hours to find out the propper way to write the first
> example. i'd like to be able to store the first list box in a variable
> and call its change or choose method..
>
> Eelco
>

Re: [shoes] [green_shoes]:symbol vs .method

From:
ashbb
Date:
2011-03-04 @ 14:54
Hi Eelco and Elias,

Thank you for the helpful information, Elias.
Yes, this syntax is Ruby's style.

But in the case of latter snippet Eelco wrote in the first mail.
Sorry, it doesn't work with Green Shoes.
Because I've not implemented ListBox#choose method. :-P

I'll try to implement the choose method in this weekend. ;-)

Cheers,
ashbb

Re: [shoes] [green_shoes]:symbol vs .method

From:
Elias Crespin
Date:
2011-03-04 @ 13:50
Hello Eelco,

After re-reading your mail, I figured out you already knew this....sorry for
my context blindness.

I tried this code and it works fine. Maybe now I am helpful....

Shoes.app do
   para "Choose a fruit:"
   @lb = list_box :items => ["Grapes", "Pears", "Apricots"],
     :width => 120
   @fruit = para "No fruit selected"
   @lb.choose ( "Pears" )
   @lb.change do |list|
       @fruit.text = list.text
   end
 end


Elias Crespin.


On Fri, Mar 4, 2011 at 2:12 PM, Elias Crespin <elias.crespin@gmail.com>wrote:

> Hi Eelco,
>
> This syntax is ruby's responsibility.
>
> It is required because hashes are used to implement named parameters to
> call the list_box initializer method. In the example you are calling the
> list_box constructor or initializer method with parameters items and choose.
>
> A start explanation for named parameters in ruby can be found here
> http://ruby.about.com/od/advancedruby/qt/opthash.htm
>
> You may also google "ruby named parameters" or "ruby hash method
> parameters" (without the quotes)
>
> Hope this helps.
>
> Elias Crespin.
>
>
>
> On Fri, Mar 4, 2011 at 1:42 PM, Catsquotl <catsquotl@gmail.com> wrote:
>
>> Hi,
>>
>> Can someone please explain why i can write.
>> list_box :items =>@m, :choose =>"#{@m[1]}" do
>> some code here
>> end
>>
>> but not.
>> @list = list_box :items =>@m
>> @list.choose("#{@m[1]}") do
>> some code here
>> end
>>
>> I find i am rather clueless about this and it has me searching docs and
>> experimenting for hours to find out the propper way to write the first
>> example. i'd like to be able to store the first list box in a variable
>> and call its change or choose method..
>>
>> Eelco
>>
>
>

Re: [shoes] [green_shoes]:symbol vs .method

From:
ashbb
Date:
2011-03-04 @ 14:58
Hi Elias,

Good sample snippet! Thank you. Yes, very helpful.

But I think you are executing the snippet with Red Shoes. Right?

I'll try to improve Green Shoes to work your snippet well in this weekend.
;-)

ashbb