From: Yasushi Shoji Date: 2000-09-21T06:06:13+09:00 Subject: [ruby-talk:5036] Re: A QuantumSuperposition Proposal for Ruby At Thu, 21 Sep 2000 00:12:58 +0900, Huayin Wang wrote: > I probably misunderstand your comments here, but I am not limiting it > to only Numeric. when I tried the following, it works! > > p ['a','c'].any > 'b' # true > p ['a','c'].all > 'b' # false it works because class String has a method '>'. i guess what I meant was that what's the use of class Quantum if internal object doesn't have methods like '>', '<', 'size'? is it expecting instances of class which include Comparable? [...] > however, I can't do it for string > > p 'b' > ['a','c'].any > p 'b' > ['a','c'].all i guess string doesn't call coerce. > I do not understand. and using coerce rather than my original > implementation give different results: > > Using my original implementation: > p [1,2,3].any < [2,5,6].all # true > > It print out "false" using yashi's implementation. hmm.. swapping doesn't work, huh ;p following code prints 'true' as the original. somehow if i think more about quantum, blurer it gets. i'll just wait and see what came out. regards, -- yashi def coerce(o) return Quantum.new([o], :any?), self end def >(o) case o when self.type o.states.send(o.method) { |x| self > x } when Numeric @states.send(@method) { |x| x > o } when String @states.send(@method) { |x| x > o } else raise "unexpected object of class '#{o.type.to_s}' for the argument of '>'" end end def <(o) case o when self.type o.states.send(o.method) { |x| self < x } when Numeric @states.send(@method) { |x| x < o } when String @states.send(@method) { |x| x < o } else raise "unexpected object of class '#{o.type.to_s}' for the argument of '<'" end end protected def states @states end def method @method end require 'quantum' q = Quantum.new(['a','c'], :all?) p (q > 'b') q = Quantum.new(['a','c'], :any?) p (q > 'b') q = Quantum.new([1,2,3], :any?) p (2 > q) q = Quantum.new([1,2,3], :all?) p (2 > q) a = Quantum.new([1,2,3], :any?) b = Quantum.new([2,5,6], :all?) p (a < b) q = Quantum.new(['a','c'], :any?) p ('b' > q)