首页 > 代码库 > [Ruby]Guide to return statement

[Ruby]Guide to return statement

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