I did PHP for 6 years.... sometimes its hard not to do PHP in ruby...

Today i was testing a url to see if it contains a certain string:

RUBY:
  1. response = Net::HTTP.get_response(URI.parse("http://myawesomesite")
  2. if response.body.match("my awesome text") == nil  then
  3.       return false
  4. end

and remember to do:

RUBY:
  1. response = Net::HTTP.get_response(URI.parse("http://myawesomesite")
  2. return "false" if response.body.match("my awesome text").nil?

Another thing I was working on was I had to do a multiple if statement

I will simplify it for this example:

RUBY:
  1. color = red
  2.   if (color == "red") or (color =="green") or (color == "yellow") then
  3.     print "its valid)
  4. end

In PHP I might have actually made the values into an array, and then did in_array ... but in reading the code, you see below, if in the valid values, print something. I don't want to see array!

This is more elegant:

RUBY:
  1. color = red
  2. valid_values = ["red","green","yellow"]
  3. puts "its valid" if valid_values.include? color

This seems to only work for values you'd do == on, not ===

See... programming in ruby just makes me grin :)