librelist archives

« back to archive

Fwd: I need to understand this code

Fwd: I need to understand this code

From:
Fily
Date:
2012-01-06 @ 02:32

Sent from my iPhone

Begin forwarded message:

> From: Filemon Salas <fs.dolphin@gmail.com>
> Date: January 5, 2012 7:51:34 PM CST
> To: shoes@librelist.com
> Subject: I need to understand this code
> 
> I have been practicing with Shoes and currently enjoying it.
> 
> I came across this code...
> 
>  Shoes.app :width => 400, :height => 260 do
>  flow do
>     @e = edit_line
>      button "Say it" do
>        @p.clear { para @e.text }
>      end
>    end
> 
>    @p = flow
>  end
> 
> but then I started wondering why the  @p.clear { para @e.text } and the
> @p = flow
> why not just...
> 
>  Shoes.app :width => 400, :height => 260 do
>    flow do
>     @e = edit_line
>     button "Say it" do
>       para @e.text
>      end
>    end
>  end
> 
> can someone explain this please?
> 
> Thanks a lot!

Re: [shoes] Fwd: I need to understand this code

From:
Cecil Coupe
Date:
2012-01-06 @ 03:04
It clears the previous word displayed if you push the button twice.
Your version would append para to the display or each additional button
push. Both are correct, depending on what you want.

On Thu, 2012-01-05 at 20:32 -0600, Fily wrote:
> > Shoes.app :width => 400, :height => 260 do
> >  flow do
> >     @e = edit_line
> >      button "Say it" do
> >        @p.clear { para @e.text }
> >      end
> >    end
> > 
> >    @p = flow
> >  end
> > 
> 

Re: [shoes] Fwd: I need to understand this code

From:
Filemon Salas
Date:
2012-01-06 @ 11:10
Ok, make sense.

Now, can someone explain these two parts of code that I'm not completely
understanding?

Where did the instance variable @p came from?
@p.clear

Then later we assign flow to this variable
 @p = flow

Sorry if this is something I should know but I'm learning Ruby at the same
time.

Thanks a lot

On Thu, Jan 5, 2012 at 9:04 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

> It clears the previous word displayed if you push the button twice.
> Your version would append para to the display or each additional button
> push. Both are correct, depending on what you want.
>
> On Thu, 2012-01-05 at 20:32 -0600, Fily wrote:
> > > Shoes.app :width => 400, :height => 260 do
> > >  flow do
> > >     @e = edit_line
> > >      button "Say it" do
> > >        @p.clear { para @e.text }
> > >      end
> > >    end
> > >
> > >    @p = flow
> > >  end
> > >
> >
>
>

Re: [shoes] Fwd: I need to understand this code

From:
ashbb
Date:
2012-01-06 @ 12:16
Hi Filemon,

Good question. :)

There are two reasons.

- @p is an instance variable. So, you can use it without initialization.
Ruby assigns nil automatically.

- Ruby (also Shoes) is an interpreter. So, when you click the button, @p is
already assigned.

> I'm learning Ruby at the same time.
Fantastic! Enjoy Ruby programming with Shoes. :)

Hope this helps,
ashbb

Re: [shoes] Fwd: I need to understand this code

From:
Filemon Salas
Date:
2012-01-06 @ 12:38
Awesome! I didn't know instance variables didn't need to be initialized.
Now what are we basically telling shoes by assigning @p to flow?

Sorry if your previous response should answer this question.

Thanks

On Fri, Jan 6, 2012 at 6:16 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi Filemon,
>
> Good question. :)
>
> There are two reasons.
>
> - @p is an instance variable. So, you can use it without initialization.
> Ruby assigns nil automatically.
>
> - Ruby (also Shoes) is an interpreter. So, when you click the button, @p
> is already assigned.
>
>
> > I'm learning Ruby at the same time.
> Fantastic! Enjoy Ruby programming with Shoes. :)
>
> Hope this helps,
> ashbb
>

Re: [shoes] Fwd: I need to understand this code

From:
ashbb
Date:
2012-01-06 @ 12:57
Hi Filemon,

> what are we basically telling shoes by assigning @p to flow?
Ah,...do you want to know what the `@p = flow` means?

- flow is a Shoes method.
  Look at this: http://shoesrb.com/manual/Element.html#flow
  If you write `flow`, Shoes creates an invisible box.

- `@p =` means to hold the value (in this case, an object of Shoes::Flow
class) as @p.

Sorry for my poor English,
ashbb