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/0321509242)
>    RUBY FOR RAILS (http://www.manning.com/black)
> * Ruby/Rails training
>      & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)
>
>