[Rubygems-developers] UserInteraction capture capability implemented

Curt Hibbs curt at curthibbs.us
Thu Jun 17 08:21:34 EDT 2004


This is good stuff Rich! I will make good use of it in the RubyGems browser.

Curt

> -----Original Message-----
> From: rubygems-developers-bounces at rubyforge.org
> [mailto:rubygems-developers-bounces at rubyforge.org]On Behalf Of Richard
> Kilmer
> Sent: Wednesday, June 16, 2004 11:18 PM
> To: rubygems-developers at rubyforge.org
> Subject: [Rubygems-developers] UserInteraction capture capability
> implemented
>
>
> All,
>
> As I said in a prior post about the new UserInteraction module, I
> implemented a class that hooks (through replacing) the module methods and
> provides you a means of capturing the interaction.
>
> Here is an example
>
> require 'rubygems/user_interaction'
>
> # to demonstrate closure
> foo = 5
>
> o = Object.new
>
> # add the UserInteraction module
> o.extend Gem::UserInteraction
>
> o.say 'hello' #=> 'hello'
>
> # capture the interaction
> ui = Gem::UserInteraction.capture
>
> # now redefine the 'say' method
> ui.on_say do |statement|
>   puts "you said: #{statement} and foo is: #{foo}"
> end
> o.say 'bar' #=> 'you said: bar and foo is: 5'
>
> So, for each method in the UserInteraction module, once you call #capture
> you get the Capture object (like 'ui' above) and can then create a block
> with a corresponding:
>
>   ui.on_<method> do |param1, ...|
>     #do something here
>   end
>
> If you don't capture a method with an on_<method> method then that method
> does nothing.  In other words, when you capture interaction, you
> get rid of
> ALL the existing modules methods and only implement the ones you
> want.  Oh,
> and the last capture wins!...if you call capture twice, the last
> capture is
> the one that has the hook (the prior capture's methods are replaced).
>
> This will be the basis for unit testing the cmd_manager stuff and also can
> be used by a GUI framework (Curt?) to capture IO as well.
>
> I will begin writing a cmd_manager unit test file a bit later.
>
> Best,
>
> Rich
>
>
> _______________________________________________
> Rubygems-developers mailing list
> Rubygems-developers at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rubygems-developers
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.699 / Virus Database: 456 - Release Date: 6/4/2004
>



More information about the Rubygems-developers mailing list