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)