, rb_sym_intern.
, (.. '%{a} % {}), , Hash .
, rb_check_symbol_cstr, Ruby.
If you want to intercept only the values ββthat exist in Hash, you can add your code to another after nextvalue == Qundef.
Please note: this will require interpolation.
If you want to do this without requiring interpolation ...
An ugly parser made on the fly for this:
str = '%% %{a} %%{b} %%%{c} %%%%{d}'
is_escaped = false
list = []
i = 0
while i < str.length
c = str[i]
if is_escaped
is_escaped = false
elsif c == '%'
is_escaped = true
elsif c == '{'
pos = str.index('}', i + 1)
if pos == nil
puts "unmatched %{ in string"
break
end
list.push(str.slice(i + 1, pos - i - 1))
i = pos
end
i += 1
end
puts list
source
share