librelist archives

« back to archive

lang_cards - variable out of scope?

lang_cards - variable out of scope?

From:
Sebastjan Hribar
Date:
2014-01-22 @ 20:22
Hi,

I've just re-factored my first ruby and shoes learning project and I 
have one open issue. This is a simple flashcard application for 
vocabulary [1]. The problem occurs when I want to list all the 
flashcards and somehow the variable for database seems to be out of 
scope. Lines from 42 - 59 in [2].

In  my initial version this has worked, but there was just one database 
to be used and it was predefined and declared at the beginning. This 
version supports multiple databases and even if you select and activate 
one it doesn't get passed to the respective block.

The obvious question: what am I doing wrong?



Additional notes:
- I've also used this project to learn about the project/gem folders and 
hence the structure...
- I wanted to port this to shoes4 but I ran into some jruby issues again 
and it'll take some time...
- I've tried to follow the ruby/shoes styleguides and best practices to 
the best of my knowledge, but I'd be grateful if someone can point out 
the parts where I failed in doing so (I haven't yet commented the code 
sufficiently).



[1] https://github.com/sebastjan-hribar/lang_cards
[2] 
https://github.com/sebastjan-hribar/lang_cards/blob/master/lib/lang_cards.rb

regards,
seba

Re: [shoes] lang_cards - variable out of scope?

From:
Tobias Pfeiffer
Date:
2014-01-22 @ 21:01
Hi there,

my guess would be that window opens a new context, e.g. it starts a new 
window which has a new context/stuff is evaluated in the context of 
this window. That's why @db falls out of scope - it's an instance 
variable bound to the first window.

Just my guess - didn't try it and am not too familiar with the shoes3 
inner workings :-)

Cheers,
Tobi

On Wed 22 Jan 2014 09:22:28 PM CET, Sebastjan Hribar wrote:
> Hi,
>
> I've just re-factored my first ruby and shoes learning project and I
> have one open issue. This is a simple flashcard application for
> vocabulary [1]. The problem occurs when I want to list all the
> flashcards and somehow the variable for database seems to be out of
> scope. Lines from 42 - 59 in [2].
>
> In  my initial version this has worked, but there was just one database
> to be used and it was predefined and declared at the beginning. This
> version supports multiple databases and even if you select and activate
> one it doesn't get passed to the respective block.
>
> The obvious question: what am I doing wrong?
>
>
>
> Additional notes:
> - I've also used this project to learn about the project/gem folders and
> hence the structure...
> - I wanted to port this to shoes4 but I ran into some jruby issues again
> and it'll take some time...
> - I've tried to follow the ruby/shoes styleguides and best practices to
> the best of my knowledge, but I'd be grateful if someone can point out
> the parts where I failed in doing so (I haven't yet commented the code
> sufficiently).
>
>
>
> [1] https://github.com/sebastjan-hribar/lang_cards
> [2]
> https://github.com/sebastjan-hribar/lang_cards/blob/master/lib/lang_cards.rb
>
> regards,
> seba

Re: [shoes] lang_cards - variable out of scope?

From:
Sebastjan Hribar
Date:
2014-01-23 @ 05:31
Hi,

I agree. I think it's similar to the scenario when I create a new 
database and it gets stored in the store_for_all_dbs.store. However, 
it's not immediately available in the listbox which reads from this 
store, so I had to put the "read transaction method" (which reads the 
store and updates the listbox items) at the end of the "create new 
database" block (lines 66-81). I have this "refreshes" implemented 
several timers.

regards,
seba

Dne 22. 01. 2014 22:01, piše Tobias Pfeiffer:
> Hi there,
>
> my guess would be that window opens a new context, e.g. it starts a new
> window which has a new context/stuff is evaluated in the context of
> this window. That's why @db falls out of scope - it's an instance
> variable bound to the first window.
>
> Just my guess - didn't try it and am not too familiar with the shoes3
> inner workings :-)
>
> Cheers,
> Tobi
>
> On Wed 22 Jan 2014 09:22:28 PM CET, Sebastjan Hribar wrote:
>> Hi,
>>
>> I've just re-factored my first ruby and shoes learning project and I
>> have one open issue. This is a simple flashcard application for
>> vocabulary [1]. The problem occurs when I want to list all the
>> flashcards and somehow the variable for database seems to be out of
>> scope. Lines from 42 - 59 in [2].
>>
>> In  my initial version this has worked, but there was just one database
>> to be used and it was predefined and declared at the beginning. This
>> version supports multiple databases and even if you select and activate
>> one it doesn't get passed to the respective block.
>>
>> The obvious question: what am I doing wrong?
>>
>>
>>
>> Additional notes:
>> - I've also used this project to learn about the project/gem folders and
>> hence the structure...
>> - I wanted to port this to shoes4 but I ran into some jruby issues again
>> and it'll take some time...
>> - I've tried to follow the ruby/shoes styleguides and best practices to
>> the best of my knowledge, but I'd be grateful if someone can point out
>> the parts where I failed in doing so (I haven't yet commented the code
>> sufficiently).
>>
>>
>>
>> [1] https://github.com/sebastjan-hribar/lang_cards
>> [2]
>> https://github.com/sebastjan-hribar/lang_cards/blob/master/lib/lang_cards.rb
>>
>> regards,
>> seba

Re: [shoes] lang_cards - variable out of scope?

From:
Cecil Coupe
Date:
2014-01-23 @ 06:45
Sometimes, $global variables  are the right solution, in spite of what 
you may have learned. Shoes apps  tend to be small (lines of code), 
exploratory or both. If a Ruby $var that lives across Shoes 
Windows/app/Contexts  works, then use it.  Once you understand why it 
works (or doesn't) then you can 'purify' it later, if need be.

--Cecil
On 01/22/2014 10:31 PM, Sebastjan Hribar wrote:
> Hi,
>
> I agree. I think it's similar to the scenario when I create a new
> database and it gets stored in the store_for_all_dbs.store. However,
> it's not immediately available in the listbox which reads from this
> store, so I had to put the "read transaction method" (which reads the
> store and updates the listbox items) at the end of the "create new
> database" block (lines 66-81). I have this "refreshes" implemented
> several timers.
>
> regards,
> seba
>
> Dne 22. 01. 2014 22:01, piše Tobias Pfeiffer:
>> Hi there,
>>
>> my guess would be that window opens a new context, e.g. it starts a new
>> window which has a new context/stuff is evaluated in the context of
>> this window. That's why @db falls out of scope - it's an instance
>> variable bound to the first window.
>>
>> Just my guess - didn't try it and am not too familiar with the shoes3
>> inner workings :-)
>>
>> Cheers,
>> Tobi
>>
>> On Wed 22 Jan 2014 09:22:28 PM CET, Sebastjan Hribar wrote:
>>> Hi,
>>>
>>> I've just re-factored my first ruby and shoes learning project and I
>>> have one open issue. This is a simple flashcard application for
>>> vocabulary [1]. The problem occurs when I want to list all the
>>> flashcards and somehow the variable for database seems to be out of
>>> scope. Lines from 42 - 59 in [2].
>>>
>>> In  my initial version this has worked, but there was just one database
>>> to be used and it was predefined and declared at the beginning. This
>>> version supports multiple databases and even if you select and activate
>>> one it doesn't get passed to the respective block.
>>>
>>> The obvious question: what am I doing wrong?
>>>
>>>
>>>
>>> Additional notes:
>>> - I've also used this project to learn about the project/gem folders and
>>> hence the structure...
>>> - I wanted to port this to shoes4 but I ran into some jruby issues again
>>> and it'll take some time...
>>> - I've tried to follow the ruby/shoes styleguides and best practices to
>>> the best of my knowledge, but I'd be grateful if someone can point out
>>> the parts where I failed in doing so (I haven't yet commented the code
>>> sufficiently).
>>>
>>>
>>>
>>> [1] https://github.com/sebastjan-hribar/lang_cards
>>> [2]
>>> https://github.com/sebastjan-hribar/lang_cards/blob/master/lib/lang_cards.rb
>>>
>>> regards,
>>> seba

Re: [shoes] lang_cards - variable out of scope?

From:
Sebastjan Hribar
Date:
2014-01-23 @ 07:47
Thank you Cecil. I changed the instance variable to global, but still 
nothing, so I examined the block for the new window again and I made a 
mistake in the "unless" block. It works now also with the instance variable.

thank you.
regards,
seba

Dne 23. 01. 2014 07:45, piše Cecil Coupe:
> Sometimes, $global variables  are the right solution, in spite of what
> you may have learned. Shoes apps  tend to be small (lines of code),
> exploratory or both. If a Ruby $var that lives across Shoes
> Windows/app/Contexts  works, then use it.  Once you understand why it
> works (or doesn't) then you can 'purify' it later, if need be.
>
> --Cecil
> On 01/22/2014 10:31 PM, Sebastjan Hribar wrote:
>> Hi,
>>
>> I agree. I think it's similar to the scenario when I create a new
>> database and it gets stored in the store_for_all_dbs.store. However,
>> it's not immediately available in the listbox which reads from this
>> store, so I had to put the "read transaction method" (which reads the
>> store and updates the listbox items) at the end of the "create new
>> database" block (lines 66-81). I have this "refreshes" implemented
>> several timers.
>>
>> regards,
>> seba
>>
>> Dne 22. 01. 2014 22:01, piše Tobias Pfeiffer:
>>> Hi there,
>>>
>>> my guess would be that window opens a new context, e.g. it starts a new
>>> window which has a new context/stuff is evaluated in the context of
>>> this window. That's why @db falls out of scope - it's an instance
>>> variable bound to the first window.
>>>
>>> Just my guess - didn't try it and am not too familiar with the shoes3
>>> inner workings :-)
>>>
>>> Cheers,
>>> Tobi
>>>
>>> On Wed 22 Jan 2014 09:22:28 PM CET, Sebastjan Hribar wrote:
>>>> Hi,
>>>>
>>>> I've just re-factored my first ruby and shoes learning project and I
>>>> have one open issue. This is a simple flashcard application for
>>>> vocabulary [1]. The problem occurs when I want to list all the
>>>> flashcards and somehow the variable for database seems to be out of
>>>> scope. Lines from 42 - 59 in [2].
>>>>
>>>> In  my initial version this has worked, but there was just one database
>>>> to be used and it was predefined and declared at the beginning. This
>>>> version supports multiple databases and even if you select and activate
>>>> one it doesn't get passed to the respective block.
>>>>
>>>> The obvious question: what am I doing wrong?
>>>>
>>>>
>>>>
>>>> Additional notes:
>>>> - I've also used this project to learn about the project/gem folders and
>>>> hence the structure...
>>>> - I wanted to port this to shoes4 but I ran into some jruby issues again
>>>> and it'll take some time...
>>>> - I've tried to follow the ruby/shoes styleguides and best practices to
>>>> the best of my knowledge, but I'd be grateful if someone can point out
>>>> the parts where I failed in doing so (I haven't yet commented the code
>>>> sufficiently).
>>>>
>>>>
>>>>
>>>> [1] https://github.com/sebastjan-hribar/lang_cards
>>>> [2]
>>>> https://github.com/sebastjan-hribar/lang_cards/blob/master/lib/lang_cards.rb
>>>>
>>>> regards,
>>>> seba
>

Re: [shoes] lang_cards - variable out of scope?

From:
Sebastjan Hribar
Date:
2014-01-23 @ 07:59
as it turns out, I still need the global variable...

regards
seba

Dne 23. 01. 2014 07:45, piše Cecil Coupe:
> Sometimes, $global variables  are the right solution, in spite of what
> you may have learned. Shoes apps  tend to be small (lines of code),
> exploratory or both. If a Ruby $var that lives across Shoes
> Windows/app/Contexts  works, then use it.  Once you understand why it
> works (or doesn't) then you can 'purify' it later, if need be.
>
> --Cecil
> On 01/22/2014 10:31 PM, Sebastjan Hribar wrote:
>> Hi,
>>
>> I agree. I think it's similar to the scenario when I create a new
>> database and it gets stored in the store_for_all_dbs.store. However,
>> it's not immediately available in the listbox which reads from this
>> store, so I had to put the "read transaction method" (which reads the
>> store and updates the listbox items) at the end of the "create new
>> database" block (lines 66-81). I have this "refreshes" implemented
>> several timers.
>>
>> regards,
>> seba
>>
>> Dne 22. 01. 2014 22:01, piše Tobias Pfeiffer:
>>> Hi there,
>>>
>>> my guess would be that window opens a new context, e.g. it starts a new
>>> window which has a new context/stuff is evaluated in the context of
>>> this window. That's why @db falls out of scope - it's an instance
>>> variable bound to the first window.
>>>
>>> Just my guess - didn't try it and am not too familiar with the shoes3
>>> inner workings :-)
>>>
>>> Cheers,
>>> Tobi
>>>
>>> On Wed 22 Jan 2014 09:22:28 PM CET, Sebastjan Hribar wrote:
>>>> Hi,
>>>>
>>>> I've just re-factored my first ruby and shoes learning project and I
>>>> have one open issue. This is a simple flashcard application for
>>>> vocabulary [1]. The problem occurs when I want to list all the
>>>> flashcards and somehow the variable for database seems to be out of
>>>> scope. Lines from 42 - 59 in [2].
>>>>
>>>> In  my initial version this has worked, but there was just one database
>>>> to be used and it was predefined and declared at the beginning. This
>>>> version supports multiple databases and even if you select and activate
>>>> one it doesn't get passed to the respective block.
>>>>
>>>> The obvious question: what am I doing wrong?
>>>>
>>>>
>>>>
>>>> Additional notes:
>>>> - I've also used this project to learn about the project/gem folders and
>>>> hence the structure...
>>>> - I wanted to port this to shoes4 but I ran into some jruby issues again
>>>> and it'll take some time...
>>>> - I've tried to follow the ruby/shoes styleguides and best practices to
>>>> the best of my knowledge, but I'd be grateful if someone can point out
>>>> the parts where I failed in doing so (I haven't yet commented the code
>>>> sufficiently).
>>>>
>>>>
>>>>
>>>> [1] https://github.com/sebastjan-hribar/lang_cards
>>>> [2]
>>>> https://github.com/sebastjan-hribar/lang_cards/blob/master/lib/lang_cards.rb
>>>>
>>>> regards,
>>>> seba
>