Principais perguntas e respostas de entrevista e testes online
Plataforma educacional para preparacao de entrevistas, testes online, tutoriais e pratica ao vivo

Desenvolva habilidades com trilhas de aprendizado focadas, simulados e conteudo pronto para entrevistas.

WithoutBook reune perguntas de entrevista por assunto, testes praticos online, tutoriais e guias comparativos em um unico espaco de aprendizado responsivo.

Preparar entrevista

Ruby On Rails perguntas e respostas de entrevista

Question: How can you implement method overloading in Ruby on Rails?
Answer:

This ones a tricky question. If you have a background in Java then you must know that method overloading is simply multiple methods with same name but different signatures/parameters.

In the case of Ruby method overloading is not supported. 

However, it does support the overall goal of passing variable number of parameters to the same method. You would implement it like this:

class MyClass  
  def initialize(*args)  
    if args.size < 2  || args.size > 3  
      puts 'This method takes either 2 or 3 arguments'  
    else  
      if args.size == 2  
        puts 'Found two arguments'  
      else  
        puts 'Found three arguments'  
      end  
    end  
  end  
end  

The output can be seen here:

MyClass.new([10, 23], 4, 10)  
Found three arguments
MyClass.new([10, 23], [14, 13]) 
Found two arguments

SO: You can get the same effect as method overloading but you just have to manage the number of variables inside your method itself.

Salvar para revisao

Adicione este item aos favoritos, marque-o como dificil ou coloque-o em um conjunto de revisao.

Abrir minha biblioteca de aprendizado
Isto e util? Sim Nao

Mais uteis segundo os usuarios:

Copyright © 2026, WithoutBook.