Logan Capaldo wrote:
>> What exactly do you intend to achieve with ".respond_to? '>'"?
> or as you mentioned ===

Thanks for the tips about Regexp#===, guys.

However, I didn't mean for anyone to focus on the details of 
String#vogon?, I only wanted to ask whether people considered it 
acceptable practice to even create String#vogon?.

The other responses which gave "why don't you do X instead" look like a 
parent giving into the whinings of a spoiled brat, and I thought the 
philosophy of Ruby was that computers and software are our slaves, not 
the other way around.

> This pattern could help in some cases, but doesn't address a number of
common use cases in which you don't create the string. Like when the
string came out of a library you call, or you are implementing a library
and the string was an argument.

This is indeed one of the problems with not extending String itself.

Are we phobic to change core classes because one file/app/library might 
expect the method to behave one way, while another would expect 
something else?

--- human.rb
class String
  def tasty_food?
    /pizza|sushi|curry|steak/ === self
  end
end
--- EOF
--- martian.rb
class String
  def tasty_food?
    /roaches|slime mold|pond scum|worms/ === self
  end
end
--- EOF
--- intergalactic-dinner-party.rb
require 'human'
require 'martian'
foods = load_food_array
foods.each do |food|
    serve food if food.tasty_food?
end
--- EOF

So far, I don't feel convinced that it's a bad idea to create 
String#vogon?.

Pistos

-- 
Posted via http://www.ruby-forum.com/.