標籤:1.puts "Hello"This write "Hello" to the screen with a new line tailed to.print "Hello"Just like puts, but without new line. 2."You know nothing".lengthThis output the string length."Jon Snow".reverse"wonS noJ""OVERWATCH".downcase #--->
標籤:Is there a method in Ruby that takes an array, and counts all unique elements and their occurrences and passes them back as a hash?For example [‘A‘,‘A‘,‘A‘,‘A‘,‘B‘,‘B‘,‘C‘].method> {‘A‘ => 4, ‘B‘ => 2, ‘C‘ => 1}Something like
標籤:系統需求首先確定作業系統環境,不建議在 Windows 上面搞,所以你需要用:Mac OS X任意 Linux 發行版本(Ubuntu,CentOS, Redhat, ArchLinux ...)強烈新手使用 Ubuntu 省掉不必要的麻煩!以下代碼地區,帶有 $ 打頭的表示需要在控制台(終端)下面執行(不包括 $ 符號)步驟0 - 安裝系統需要的包# For Mac # 先安裝 [Xcode](http://developer.apple.com/xcode/)
標籤:#!/usr/bin/rubyputs "Hello, Ruby, what is your name?"$name = STDIN.getsputs "Hi, I am "+$namedef welcome(name,a = 9,b = 9,*c) puts "Hi #{name}" c.each{|x| print "#{x}"}# print "a = "+ $a a = 10; b = 11# print "Hi, b" + $b res =
標籤: When you first started coding, errors were probably the last thing you wanted to see.After all, it’s not a far stretch to associate “error” with “I messed up”.Hopefully by now you’ve come to appreciate