[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: how to check for block in an evaled method?

Logan Capaldo

8/27/2007 3:30:00 AM

On 8/26/07, Nasir Khan <rubylearner@gmail.com> wrote:

>
> I get that. But the question is, is there a way to check for a block and
> then yield in a defined method, as was my naive intention?
>
Stage 1) Upgrade to ruby 1.9 or later. 2) define_method(:foo) { |arg, &block|
if block then block.call else puts arg
}

Alternative route is to use string eval.
>
> Thanks
> Nasir
>

3 Answers

dblack

8/27/2007 10:43:00 AM

0

Logan Capaldo

8/27/2007 11:42:00 PM

0

On 8/27/07, dblack@wobblini.net <dblack@wobblini.net> wrote:
> Hi --
>
> On Mon, 27 Aug 2007, Logan Capaldo wrote:
>
> > On 8/26/07, Nasir Khan <rubylearner@gmail.com> wrote:
> >
> >>
> >> I get that. But the question is, is there a way to check for a block and
> >> then yield in a defined method, as was my naive intention?
> >>
> > Stage 1) Upgrade to ruby 1.9 or later. 2) define_method(:foo) { |arg, &block|
> > if block then block.call else puts arg
> > }
>
> I'm not sure. Here's my little test:
>
>
> class C
> define_method(:foo) { |arg, &block|
> if block then block.call else puts arg end
> }
> end
>
> c = C.new
> c.foo(3) { puts "hi" }
>
> which gives me:
>
> $ /usr/local/lib/ruby-svn/bin/ruby -v block9.rb
> ruby 1.9.0 (2007-08-25 patchlevel 0) [i686-darwin8.10.1]
> 3
>
> This is on 1/2-cup coffee so I may well be not seeing something I'm
> doing wrong.
>
Well alrighty then... I don't know what thats about and I haven't
installed 1.9ish in a while. I'm surprised that doesn't work but is
valid syntax though. I wonder what is actually happening? Assigning
the (non-existant, and I think impossible) block passed to class C...?
>
> David
>
> --
> * Books:
> RAILS ROUTING (new! http://www.awprofessional.com/title/...)
> RUBY FOR RAILS (http://www.manning...)
> * Ruby/Rails training
> & consulting: Ruby Power and Light, LLC (http://www.r...)
>
>

Mason Barge

11/14/2012 7:02:00 PM

0

On Tue, 13 Nov 2012 22:53:38 +0000 (UTC), "Adam H. Kerman"
<ahk@chinet.com> wrote:

>Mason Barge <masonbarge@gmail.com> wrote:
>
>>I love NotePad and WordPad for that reason. But I don't know of any
>>current equivalent for a graphics viewer, that will load in half a second
>>and do nothing but let you open a graphic, display it, and give you basic
>>info about it.
>
>Notepad is one lousy text editor. It lacks the ability to purge characters
>that make a document not plain text, displaying them instead as undisplayable
>characters. I have to use Word's plain text feature for that.

You might be confusing formatting marks with characters, since it has good
support for characters. So, what, you're trying to use it to open or copy
a .doc or .rtf file?

Notepad is great at what it does. If, for instance, you want to write
some quick HTML or any other computer code, or make notes in the lightest
format possible, it's the bees knees. It's the only native Win
application that will do that, in fact.

Whatever you're trying to do with it does not make it "lousy". It's very
limited and you're trying to use it for something it's not intended to do.