Lazy.rb 0.9.5 -- transparent futures!

MenTaLguY wrote:

On Fri, 2006-02-24 at 10:13 +0900, Jim W. 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


– Jim W.

On 2/25/06, MenTaLguY [email protected] 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

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

Hi mental. Thank you for the really nice library.

I’m sorry if this bothers you, but I have no idea what “circular
programming” is. Could you give me an example? Especially, what does
“matryoshka = demand( promise { |result| [result] } )” mean?

I also suggest that you should upload the description posted here to
your own website(http://moonbase.rydia.net/software/lazy.rb/), so that
people can find out what lazy.rb really is. IMHO, RDoc itself is not
sufficient.

  • Minkoo S.