Created
August 18, 2014 04:30
-
-
Save Code-Hex/f5319a7611f3ec6b57e5 to your computer and use it in GitHub Desktop.
rubyの練習。その1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "hello\n"; | |
sun = String.new "String.new\n"; | |
print sun; | |
for num in 1..3 | |
print num,"\n"; | |
end | |
print "end\n"; | |
print %Q{"ダブルクウォーテーションの場合は%Q"},"\n"; | |
print %q{'シングルの場合は%q'},"\nでエスケープ\n"; | |
str1="Welcome" | |
space=" " | |
str2="vacation\n" # 改行すれば ; はいらない | |
print str1+space+str2 | |
very="very " | |
good="good" | |
n="\n" # 改行 | |
print very * 3 + good + n * 2 | |
print "数値のクラスを知る。\n" | |
print %Q{"文字列"のクラスは },"文字列".class,n | |
print <<"EOF" | |
じゃあ数値はどうなるか? | |
例 10 とか 3.14 | |
これらはC言語だと int や float で型だったね | |
じゃあ class はどうなってるんだろう? | |
EOF | |
print n | |
print "10 ",10.class,"\n" | |
print "3.14 ",3.14.class,"\n"*3 | |
truefalse = [true, false, nil] | |
# for でも同じようにかける | |
truefalse.each{|var| | |
puts var.class | |
} | |
print n*2 | |
result = ["これで","forと","eachが","分かったんじゃないかな?"] | |
for array in result | |
print array | |
end | |
print n*2 | |
result2 = ["forって","書き方","いっぱい","あるんだね"] | |
result2.each do |may| | |
print may | |
end | |
print n*2 | |
print result.length,n # 配列の個数 | |
print result2.size,n #lengthと同じ | |
print n*2 | |
name = "山田" | |
print name,n | |
print name.size,"文字",n*2 | |
name << " 太郎" #文字列の追加 | |
print name,n | |
print name.size,"文字",n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perlを極めるためのruby