On 27/12/08 22:38, Anton Sharonov wrote:
> Hi, All,
>
> I have a following simple example, which illustrates my use case:
>
> function! TestStringIf()
> ruby<< EOF
> def bad_string()
> return "'abc'" # can be very long string
> end
> # Is there any better way then gsub(...) ?
> VIM::command("let result_viml = '" + bad_string().gsub("'", "''") + "'")
> EOF
> return result_viml
> endfunction
> echom "result_viml is " . TestStringIf()
>
> In my real scenario bad_string() is ruby function which can
> return arbitrary string, containing any bytes, excepting 0 (this
> string is received over network from server). The length of the
> string can be very big (I can imagine lengths of ~100 KB). I'm
> new to both ruby and ruby's integration with VIM, therefore my
> question: do I do it right way now - using gsub() to escape "'"
> characters and VIM::command("let ...") to pass the string to VIML
> variable? Are there better / more efficient ways of copying
> string from ruby variable to the VIML variable ?
>
> --
> Anton
Unless you want to keep the result after displaying it, you could also
use the VIM::message() function to display the message in Vim directly
from Ruby.
see ":help if_ruby.txt".
Best regards,
Tony.
--
[clop clop]
MORTICIAN: Who's that then?
CUSTOMER: I don't know.
MORTICIAN: Must be a king.
CUSTOMER: Why?
MORTICIAN: He hasn't got shit all over him.
The Quest for the Holy Grail (Monty
Python)
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---