[ANN] lazy.rb 0.9.5 -- transparent futures!

I have a rather mutated version of BlankSlate (as a module) which
supports both of these.
You can use it something like this:

class Foo
  include BlankSlate
  hide :instance_eval
  restore :class
end

Foo.new.instance_eval{} #=> raises NoMethodError
Foo.new.class #=> Foo

Is there any chance these features could be included in the gem? I'd
love to use it myself, but I need my various changes to it too.

Here's the code:

  module BlankSlate
    module ClassMethods
      def restore(*names)
        names.each{|name| alias_method name, "##{name}"}
      end
      def hide(*names)
        names.each do|name|
          undef_method name if instance_methods.include?(name.to_s)
        end
      end
    end

    def BlankSlate.included(othermod)
      othermod.instance_eval {
        instance_methods.each { |m|
          #nothing is thrown away forever, just renamed in a strange way
          alias_method "##{m}", m #archive m
          undef_method m unless m =~ /^__/ || m=='instance_eval'
        }
        extend BlankSlate::ClassMethods
      }
    end
  end

···

On 2/25/06, MenTaLguY <mental@rydia.net> wrote:

Hmm. Okay, for lazy.rb there are a couple things I would need from
BlankSlate:

- the ability to "let through" a few additional methods
   (just Object#class at the moment, but there may be more later)

- to be able to hide Object#instance_eval

MenTaLguY wrote:

Yep, it was a bug in the new RubyGems server-side indexing software.
Should be fixed now. Give it another try...

   gem install blankslate -s http://onestepback.org/betagems

Hmm. Okay, for lazy.rb there are a couple things I would need from
BlankSlate:

- the ability to "let through" a few additional methods
   (just Object#class at the moment, but there may be more later)

- to be able to hide Object#instance_eval

Maybe the best thing would be a factory that creates customized
BlankSlate-like classes, roughly similar to the way Struct works.

Instance_eval can be hidden with a call to hide. This class method is
trivial to reimplement, although the general case might need something
like Caleb suggested.

  class BS < BlankSlate
    hide :instance_eval
    def class
      BS
    end
  end

···

On Fri, 2006-02-24 at 10:13 +0900, Jim Weirich wrote:

--
-- Jim Weirich

--
Posted via http://www.ruby-forum.com/\.

Good idea, thanks!

···

On 2/24/06, mental@rydia.net <mental@rydia.net> wrote:

Quoting Daniel Nugent <nugend@gmail.com>:

> Mental, could I perchance persuade you to add an optional
> parameter to
> the Future initializer that accepts a block to be run inside the
> rescue clause of the Future's thread?
>
> future(lambda{|exception| lock.synchronize{subscribers.each{|s|
> s.raise(exception)}}}){holy_crap_long_execution}

How about:

future {
   begin
     holy_crap_long_execution
   rescue Exception => exception
     lock.synchronize do
       subscribers.each { |s| s.raise( exception ) }
     end
     raise
   end
}

?

That might be a bit longer, but it seems clearer what's going on.

-mental

--
-Dan Nugent