librelist archives

« back to archive

How to make a call it later style?

How to make a call it later style?

From:
yeer kunth
Date:
2012-03-31 @ 15:12
hi, all
this is a very common example

Shoes.app do
   @var = ''
   def foo
   end
end

But I am trying to make a deferred evaluation,
for example:
blk = lambda{
   @var
    def foo
    end
}
Shoes.app &blk

Of course it's failed.
Do you guys know any other way to implement it?

Re: [shoes] How to make a call it later style?

From:
Steve Klabnik
Date:
2012-03-31 @ 15:22
Blocks and lambdas aren't the same thing, unfortunately. However, this
works for me:

blk = Proc.new do
  alert "foo"
end

Shoes.app &blk

Re: [shoes] How to make a call it later style?

From:
yeer kunth
Date:
2012-03-31 @ 15:30
hi steve,
thank you.

I also find another way,
def run
  Shoes.app do
      @var
      def foo
      end
  end
end

run

but it looks so terrible :P


On Sat, Mar 31, 2012 at 11:22 PM, Steve Klabnik <steve@steveklabnik.com>wrote:

> Blocks and lambdas aren't the same thing, unfortunately. However, this
> works for me:
>
> blk = Proc.new do
>  alert "foo"
> end
>
> Shoes.app &blk
>