- '$0': ライブラリとして使用された場合(require)、呼び出し元を表示
- '__FILE__': 実行中のプログラム名を表示
requireされたときは"#Code"は実行されない。 短いコードなら、テストを書いておくのが良さげ。
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'yaml' | |
require 'csv' | |
class GeneratorYmlProps | |
def initialize(hostlst) | |
@hostlst = hostlst | |
@property = Hash.new { |hash,key| hash[key] ={} } |
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'webrick' | |
config = { | |
:Port => 10080, | |
:DocumentRoot => '.', | |
} |
# Read(line by line) | |
File.open 'fname' do |f| | |
f.each_line do |line| | |
puts line | |
end | |
end | |
# Read(Slurp) | |
File.open 'fname' do |f| | |
puts f.read |
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'optparse' | |
params = ARGV.getopts('f:') | |
prg_name = File.basename(__FILE__) | |
usage = <<-EOS | |
------------------------- | |
Usage: parse [options] |
# collect:upload_files | |
namespace :collect do | |
desc 'deploy files' | |
task :upload_files, roles => :local do | |
upload_dir= File.expand_path('~/scpfiles') | |
upload_files = [ "#{upload_dir}/hoge.rb", | |
"#{upload_dir}/foodir", | |
] | |
upload_files.each do |fp| | |
fname = File.basename(fp) |
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'logger' | |
tmpl = 'hogehoge' | |
# logfile: '/tmp/test.log' logrotate: 'daily' | |
logger = Logger.new('/tmp/test.log', 'daily') | |
# logfile: '/tmp/test.log' logrotate: '10Mib/7lotate(1current+6backup)' |
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'ruby-growl/ruby_logo' | |
pass = 'himitsu' | |
title = 'From Ruby' | |
message = 'Hello Ruby' | |
g = Growl.new "localhost", "ruby-growl" |