Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Ruby Methods

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 170
    Comment on it

    Ruby Methods are similar to functions which begins with lowercase letters. It bundles one or more repeatable statements into single units.Methods are always defined before calling them.
    Syntax:
    def method_name [( [arg [= default]]...[, * arg [, &expr ]])] expr.. end

    Example:

    #!/usr/bin/ruby
    
    def test(a1="Ruby", a2="Perl")
       puts "The programming language is #{a1}"
       puts "The programming language is #{a2}"
    end
    test "C", "COBOL"
    test
    

    Output
    The programming language is C
    The programming language is C++
    The programming language is Ruby
    The programming language is Perl

 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: