Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overwrite similar methods, shorter syntax

Tags:

ruby

In a Ruby Class I overwrite three methods, and, in each method, I basically do the same thing:

class ExampleClass

  def confirmation_required?
    is_allowed && super
  end

  def postpone_email_change?
    is_allowed && super
  end

  def reconfirmation_required?
    is_allowed && super
  end

end

Is there a more compact syntax? How can I shorten the code?

like image 777
John Smith Avatar asked Jan 20 '17 17:01

John Smith


1 Answers

How about to use alias?

class ExampleClass

  def confirmation_required?
    is_allowed && super
  end

  alias postpone_email_change? confirmation_required?
  alias reconfirmation_required? confirmation_required?
end
like image 136
Heungju Kim Avatar answered Sep 30 '22 12:09

Heungju Kim