def say_goodnight(name)
result = "Good night, #{name}" ##把变量name的值替换进字符串,ruby使用#{var}.
return result
end
puts say_goodnight('Pa')
##########################################################
def say_goodnight(name)
result = "Good night, #{name.capitalize}" ##s.capitalize 第一个子母变为大写
##s.capitalize!
##Returns a copy of s with the first character converted to uppercase and the remainder to lowercase.
##"fooBar".capitalize # => "Foobar"
return result
end
puts say_goodnight('uncle')
##########################################################
$greeting = "Hello" # $greeting is a global variable
@name = "Prudence" # @name is an instance variable
puts "#$greeting, #@name"
##########################################################
def say_goodnight(name) ##不用使用return语句也可以返回
"Good night, #{name}"
end
puts say_goodnight('Ma')