x = 123
a = "This is <%= 5+6 %> and <%= 'The' + 're'%>, <%=Time.now%>. x=<%=x%>"
a.gsub!(/<%=(.*?)%>/) { eval($1).to_s }
puts a
パイプ
IO.popen("pkg_info -asc", "r") do |fp|
while fp.gets
line = $_
if line =~ /^Information for/
name = line.split[2].chop
size = "?"
comment = "?"
elsif line =~ /^Comment:/
fp.gets
comment = $_
elsif line =~ /^Package Size:/
fp.gets
size = $_.split[0]
printf "%-30s %8s %s", name, size, comment
end
end
end