In Ruby language, the return statement in the Ruby functions are interesting, Let's explore them as below:
def concatenate(name_one=nil, name_two="")
return name_one + name_two
end
name = concatenate "wuhan", "hubei"
puts name
puts concatenate("shang hai")
def string_as_return(name=nil)
return "hello, #{name}"
end
puts string_as_return()
puts string_as_return('KD')
def array_as_return(first_name, last_name)
return first_name, last_name
end
name = array_as_return("Kevin","Durant")
puts name.to_s
puts name.class
本文通过几个示例探讨了Ruby语言中函数返回值的各种用法,包括字符串拼接、返回字符串、数组等不同类型的返回值及其应用。
3692

被折叠的 条评论
为什么被折叠?



