Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call super for self

Tags:

ruby

I have a 3rd party gem with extension for String class:

class String
  def to_url
    self.gsub /\s+/, '-'
  end
end

And I have my app trying to extend String class:

class String
  def to_url
    Russian.translit self
    super
  end
end

How do I call super (to replace spaces AND do transliteration) from my app? My code does super, but skips Russian.translit self.

like image 465
ujifgc Avatar asked Sep 05 '26 12:09

ujifgc


1 Answers

There is no super to call. You should use alias_method

class String
  alias_method :old_to_url, :to_url
  def to_url
    Russian.translit(self).old_to_url
  end
end
like image 82
Serabe Avatar answered Sep 07 '26 06:09

Serabe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!