From: Ken Bloom Date: 2006-11-07T13:45:08+09:00 Subject: Re: simple mix-in example On Tue, 07 Nov 2006 00:33:00 +0000, pedro mg wrote: > Hi, > > can we consider this is a mix-in newbie example ? We are giving a new > feature to method > on our Mixin class. > > class Mixin > def initialize(a) > @a = a > end > def >(arg) > puts "Yep!" if @a > arg > end > end > > test = Mixin.new(3) > test > 1 # -> Yep! > test.> 1 # -> Yep! > test.>(1) # -> Yep! > puts "Yep, too!" if 2 > 1 # -> Yep, too! > puts "not now!" if teste < 1 # -> * > > * undefined method `<' for # (NoMethodError) > > Works as expected. Thanks, Yuck. if test > 1 puts "Yes" else puts "No" end will print out Yep! No You need to define the > operator as follows: def >(arg) puts "Yep!" if @a > arg @a > arg end so that it returns a proper value -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/