例題:hello world(hello.rb)
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% ruby ex0.rb
Hello world!
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% cat ex0.rb
puts "Hello world!"
例題:変数への代入と出力(gets.rb)
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% ruby ex1.rb
1
[bobsNewMacBook:~/Desktop/Ruby/ThreeDays] bob% cat ex1.rb
a=1
puts a
例題:getsしてputs(GetsPuts.rb)
a=gets.chomp.to_i
puts, print, printf
[bob-no-MacBook-Pro:Ruby/FiveDays/ex1] bob% !r
ruby ex1-2.rb
4
1:Input is
4
2:Input is 4
3:Input is 4.
4:Input is 4.
4
5:Input is 4.
[bob-no-MacBook-Pro:Ruby/FiveDays/ex1] bob% cat ex1-2.rb
a=gets.chomp.to_i
puts "1:Input is ",a
puts "2:Input is #{a}"
puts "3:Input is "+a.to_s+"."
print "4:Input is ",a,".\n"
p a
printf("5:Input is %4d.\n",a)
Keyword(s):
References:[MultiScale13] [RubyPrimary]