mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
18 lines
326 B
Ruby
18 lines
326 B
Ruby
|
def serb(str, var)
|
||
|
result = ''
|
||
|
str.each_line {|line|
|
||
|
if /\A!/ =~ line
|
||
|
result << $'
|
||
|
else
|
||
|
line.split(/(<%.*?%>)/).each {|x|
|
||
|
if /\A<%(.*)%>\z/ =~ x
|
||
|
result << "#{var} << (#{$1}).to_s\n"
|
||
|
else
|
||
|
result << "#{var} << #{x.dump}\n"
|
||
|
end
|
||
|
}
|
||
|
end
|
||
|
}
|
||
|
result
|
||
|
end
|