def method_name [( [arg [= default]]...[, * arg [, &expr ]])] expr.. end
def method_name expr.. end
def method_name (var1, var2) expr.. end
def method_name (var1=value1, var2=value2) expr.. end
#!/usr/bin/ruby
def test(a1="Ruby", a2="Perl")
puts "The programming language is #{a1}"
puts "The programming language is #{a2}"
end
test "C", "C++"
test
The programming language is C The programming language is C++ The programming language is Ruby The programming language is Perl
def test i = 100 j = 10 k = 0 end
#!/usr/bin/ruby def test i = 100 j = 200 k = 300 return i, j, k end var = test puts var
100 200 300
#!/usr/bin/ruby
def sample (*test)
puts "The number of parameters is #{test.length}"
for i in 0...test.length
puts "The parameters are #{test[i]}"
end
end
sample "Zara", "6", "F"
sample "Mac", "36", "M", "MCA"
The number of parameters is 3 The parameters are Zara The parameters are 6 The parameters are F The number of parameters is 4 The parameters are Mac The parameters are 36 The parameters are M The parameters are MCA
class Accounts def reading_charge end def Accounts.return_date end end
Accounts.return_date
alias method-name method-name alias global-variable-name global-variable-name
alias foo bar alias $MATCH $&
undef bar
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有