ivaneeo's blog

          自由的力量,自由的生活。

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
            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')

          posted on 2006-09-12 15:05 ivaneeo 閱讀(288) 評論(0)  編輯  收藏 所屬分類: ruby-寶石也鋒芒
          主站蜘蛛池模板: 涡阳县| 宁波市| 禹城市| 四会市| 微山县| 交口县| 营山县| 泽州县| 临安市| 西林县| 揭西县| 贡嘎县| 宝兴县| 遵义市| 武冈市| 鹰潭市| 万州区| 博兴县| 南平市| 陵川县| 新丰县| 密山市| 札达县| 嘉祥县| 和田市| 新蔡县| 太仆寺旗| 晋州市| 洛隆县| 宝清县| 开远市| 中阳县| 闵行区| 从化市| 荔波县| 怀安县| 赣榆县| 上饶市| 永城市| 郸城县| 乐陵市|