[Rubygems-developers] UserInteraction capture capability implemented

Chad Fowler chad at chadfowler.com
Thu Jun 17 08:25:20 EDT 2004


I've been doing a little goofing around with a fox browser in my free 
time, and this is working great there.  Of course, most of the browser 
isn't using the IO stuff, but this is valuable for when we have 
questions that need to be asked from deep inside the library.

Btw, I'm not necessarily planning to finish the fox browser.  Mostly 
just doing it to see what kind of problems I run into (re: our previous 
threads on design).  It has led to some minor refactoring--including 
what Rich has done here. :)

Chad


On 17/6/2004, at 8:21 AM, Curt Hibbs wrote:

> 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
>>
>
> _______________________________________________
> Rubygems-developers mailing list
> Rubygems-developers at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rubygems-developers



More information about the Rubygems-developers mailing list