Simple String Substitution

Submitted By:
david

Difficulty:
Easy

Tags:
strings

Instructions:
One of the challenges in implementing Rubeque is performing string substitution. See how well you can do.

Code:
class String
  def simple_sub(pattern, replace)
    ___
  end
end

subject = "?? == ??"

assert_equal subject.simple_sub("==", "<="), "?? <= ??"
assert_equal subject.simple_sub("abc", "def"), "?? == ??"
assert_equal subject.simple_sub("??", "fun??"), "fun?? == fun??"

naruse_answer = "Date.parse(date.sub(/(\d+)[-\/](\d\d).(\d{4})/,'\\3-\\1-\\2')).strftime('%b %d, %Y')"
assert_equal subject.simple_sub("??", naruse_answer), "#{naruse_answer} == #{naruse_answer}"  

Your Solution

Ruby 1.9.3

Back to Problems