- Äɲ䵤줿¹Ô¤Ï¤³¤Î¿§¤Ç¤¹¡£
- ºï½ü¤µ¤ì¤¿¹Ô¤Ï¤³¤Î¿§¤Ç¤¹¡£
[[Ruby]]
#contents
*¥µ¥ó¥×¥ë [#g29f5ecf]
**Hello, Ruby!¥á¥½¥Ã¥ÉÈÇ [#x79b06c8]
hello.rb
def hello
puts "Hello, Ruby!"
end
hello()
**Hello, Ruby!¥é¥¤¥Ö¥é¥êÈÇ [#x79b06c8]
helloLib.rb
def hello
puts "Hello, Ruby!"
end
hello.rb
require "helloLib"
hello()
-¥é¥¤¥Ö¥é¥ê¤ÏÊÌ¥Õ¥¡¥¤¥ë¤ÇºîÀ®¤·¡¢require ""¤ÇÆɤ߹þ¤ß¤Þ¤¹¡£
-¥é¥¤¥Ö¥é¥êÆâ³°¤ÇÍøÍѤǤ¤ë¥°¥í¡¼¥Ð¥ëÊÑ¿ô¤Ï¡¢¡Ö$ÊÑ¿ô̾¡×¤È¤·¤Þ¤¹¡£
**ÇÛÎó [#k347a635]
arLanguage = ["Ruby", "PHP", "C", "java"]
arLanguage.each { |value|
puts value
end
**grep¥³¥Þ¥ó¥É [#k25a7ad1]
grepr.rb
pattern = Regexp.new(ARGV[0])
filename = ARGV[1]
file = open(filename)
while line = file.gets
if pattern =~ line
print line
end
end
file.close
¼Â¹ÔÊýË¡
ruby grepr ¥Ñ¥¿¡¼¥ó ¥Õ¥¡¥¤¥ë̾
**case - whenʸ ʸ»úÎó°ìÃ× [#c09a7661]
arTag = ["a", "img", "pre"]
arTag.each { |tag|
case tag
when "p", "a", "i", "b", "blockquote"
print tag, " has child.\n"
when "img", "br"
print tag, " has no child.\n"
else
print tag, " cannot be used.\n"
end
}
**case - whenʸ Àµµ¬É½¸½ [#m611e9ff]
while line = gets
case line
when /^From:/i
puts "find sender!"
when /^To:/i
puts "find receiver!"
when /^Subject:/i
puts "find subject!"
when /^$:/
puts "finish!"
else
## ÆɤßÈô¤Ð¤¹
end
end
**case - whenʸ ¥ª¥Ö¥¸¥§¥¯¥È¼±ÊÌ [#dcac99ac]
arObject = ["a", 1, nil]
arObject.each { |item|
case item
when String
puts "item is String."
when Numeric
puts "item is Numeric."
else
puts "item is something."
end
}