Ruby(2008-02-07)

作者: IT Person
发布时间:2015-07-13 11:31:38

#first program
#function defination
def say_goodnight(name)
  result = "Good night, #{name}"
  return result
end

#function invoke
puts say_goodnight('Pa')

#capitalize method
def say_goodnight(name)
  result = "Good night, #{name.capitalize}"
  return result
end

puts say_goodnight('pa')

#Ruby uses a convention to help it distinguish the usage of a name:the first characters of a name indicate how the name is used.
#Local variables,method parameters,and method names should all start with a lowercase letter or with an underscore.
#Global variables are prefixed with a dollar sign($),and instance variables begin with an "at" sign(@).
#Class variables start with two "at" signs(@@).
#Finally,class names,module names,and constants must start with an uppercase letter.

标签: Ruby
来源:http://www.cnblogs.com/tongzhiyong/archive/2008/02/07/106576

推荐: