Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Variable Number of Parameters

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 172
    Comment on it

    If you declare a method that takes two parameters, on This method call , you need to pass two parameters along with it.

    But, Ruby facilitates to declare methods that can work with a variable number of parameters.

    Example

    def evon (*t)
       puts "The number of parameters is #{t.length}"
       for i in 0...t.length
          puts "The parameters are #{t[i]}"
       end
    end
    evon "Abhishek", "23", "M","B.tech"
    evon "Pranav", "21", "M", "B.tech"
    

    Output The number of parameters is 4
    The parameters are Abhishek
    The parameters are 23
    The parameters are B.tech

    The number of parameters is 4
    The parameters are Pranav
    The parameters are 21
    The parameters are M
    The parameters are B.tech

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: