Framework | Memo |
---|---|
Ruby on Rails | http://www.rubyonrails.org/ |
Sinatra | http://www.sinatrarb.com/ |
Padrino |
print "foo" # not line break puts "foo" # line break p 123 # for debug
a = 123 a = "abc" foo # local variable @foo # instance variable @@foo # class variable $foo # global variable FOO #
num = 1 num = 1.234 num = 100_000_000 num = 1 + 1 num = 1 - 1 num = 1 * 2 num = 5 / 2 # 2 num = 5.0 / 2 #2.5 num = 5 % 2 #1 i += 1 i -= 1
str1 = 'abc' str2 = "def" str3 = "a\tbc\n" str4 = "#{str1} def" #=> "abc def"
str1 = "aaa" + "bbb" str2 = ["aaa", "bbb", "ccc"].join(",")
record = "aaa,bbb,ccc".split(/,/)
substr = "abcd"[0, 2] # "ab"
idx = "abcd".index(/bc/)
ary = [100, 200, 300]
a = ary[0] #=> 100 b = ary[1] #=> 200
ary[0] = 1 ary[1] = 2
ary = [1, 2, 3] a = ary.shift #=> a=1、ary[2,3] ary.unshift(5) #=> ary[5,2,3] b = ary.pop #=> b=3, ary[5,2] ary.push(9) #=> ary[5,2,9]
if a == 1 abbr elsif b == 2 abbr else abbr end
i = 0 while i < 5 abbr i += 1 end
def sum(x, y) return x + y end p sum(1,2) #=> 3
str = File.read("foo.txt")
File.open("out.txt", "wb") do |f| f.write str end
# ruby foo.rb a.txt b.txt p ARGV #=> [a.txt, b.txt]