Rev | Line | |
---|
[18425] | 1 | #--
|
---|
| 2 | #
|
---|
| 3 | # Author:: Nathaniel Talbott.
|
---|
| 4 | # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
---|
| 5 | # License:: Ruby license.
|
---|
| 6 |
|
---|
| 7 | module Test
|
---|
| 8 | module Unit
|
---|
| 9 | module Util
|
---|
| 10 |
|
---|
| 11 | # Allows the storage of a Proc passed through '&' in a
|
---|
| 12 | # hash.
|
---|
| 13 | #
|
---|
| 14 | # Note: this may be inefficient, since the hash being
|
---|
| 15 | # used is not necessarily very good. In Observable,
|
---|
| 16 | # efficiency is not too important, since the hash is
|
---|
| 17 | # only accessed when adding and removing listeners,
|
---|
| 18 | # not when notifying.
|
---|
| 19 |
|
---|
| 20 | class ProcWrapper
|
---|
| 21 |
|
---|
| 22 | # Creates a new wrapper for a_proc.
|
---|
| 23 | def initialize(a_proc)
|
---|
| 24 | @a_proc = a_proc
|
---|
| 25 | @hash = a_proc.inspect.sub(/^(#<#{a_proc.class}:)/){''}.sub(/(>)$/){''}.hex
|
---|
| 26 | end
|
---|
| 27 |
|
---|
| 28 | def hash
|
---|
| 29 | return @hash
|
---|
| 30 | end
|
---|
| 31 |
|
---|
| 32 | def ==(other)
|
---|
| 33 | case(other)
|
---|
| 34 | when ProcWrapper
|
---|
| 35 | return @a_proc == other.to_proc
|
---|
| 36 | else
|
---|
| 37 | return super
|
---|
| 38 | end
|
---|
| 39 | end
|
---|
| 40 | alias :eql? :==
|
---|
| 41 |
|
---|
| 42 | def to_proc
|
---|
| 43 | return @a_proc
|
---|
| 44 | end
|
---|
| 45 | end
|
---|
| 46 | end
|
---|
| 47 | end
|
---|
| 48 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.