[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Question about BlankSlate.reveal [SOLVED]

Gregory Brown

1/25/2009 4:26:00 PM

On Sun, Jan 25, 2009 at 5:30 AM, Gregory Brown
<gregory.t.brown@gmail.com> wrote:

As it turns out, I was able to stop the method from binding to a
single instance without re-binding on every call. I simply changed
this code:

> ### Code pulled from blankslate.rb in the builder gem.
>
> # Redefine a previously hidden method so that it may be called on a blank
> # slate object.
> def reveal(name)
> bound_method = nil
> unbound_method = find_hidden_method(name)
> fail "Don't know how to reveal method '#{name}'" unless unbound_method
> define_method(name) do |*args|
> bound_method ||= unbound_method.bind(self)
> bound_method.call(*args)
> end
> end
> end

So that instead, it passed the UnboundMethod directly to
define_method. This does what I want and seems reasonable. Please
let me know if there are problems, otherwise, I'm a happy camper now.
:)

def reveal(name)
unbound_method = find_hidden_method(name)
fail "Don't know how to reveal method '#{name}'" unless unbound_method
define_method(name, unbound_method)
end

-greg




--
Technical Blaag at: http://blog.majesticseacr...
Non-tech stuff at: http://metametta.bl...
"Ruby Best Practices" Book now in O'Reilly Roughcuts:
http://rubybestpra...

1 Answer

Robert Klemme

1/28/2009 10:23:00 AM

0

2009/1/25 Gregory Brown <gregory.t.brown@gmail.com>:
> On Sun, Jan 25, 2009 at 5:30 AM, Gregory Brown
> <gregory.t.brown@gmail.com> wrote:
>
> As it turns out, I was able to stop the method from binding to a
> single instance without re-binding on every call. I simply changed
> this code:

> So that instead, it passed the UnboundMethod directly to
> define_method. This does what I want and seems reasonable. Please
> let me know if there are problems, otherwise, I'm a happy camper now.

Greg, thanks for sharing the result of your investigation!

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end