"Guoliang Cao" <gcao / lemurnetworks.net> schrieb im Newsbeitrag
news:15010631647.20040203093520 / lemurnetworks.net...
> Hi,
>
> I'm thinking of submitting a RCR. Here is the draft. Comments are
welcome.

[snip]

Do we need this?

16:41:55 [ruby]: ./ccase.rb
[#<struct Point x=0, y=0>, "white"]
[#<struct Point x=100, y=0>, "blue"]
[#<struct Point x=55, y=55>, "grey"]
[#<struct Point x=120, y=210>, "black"]
16:41:57 [ruby]: cat ccase.rb
#!/usr/bin/ruby

Point = Struct.new( :x, :y )

class CondWhite
  def self.===(point); (0..50) === point.x or (150..200) === point.x; end
end

class CondBlue
  def self.===(point); (50..150) === point.x and (0..50) === point.y; end
end

class CondGrey
  def self.===(point); (50..100) === point.x and (50..200) === point.y;
end
end


points = [
  Point.new( 0, 0 ),
  Point.new( 100, 0 ),
  Point.new( 55, 55 ),
  Point.new( 120, 210 ),
]

points.each do |point|
  case point
  when CondWhite; p [point, "white"]
  when CondBlue; p [point, "blue"]
  when CondGrey; p [point, "grey"]
  else; p [point, "black"]
  end
end
16:42:00 [ruby]:

Regards

    robert