Skip to content

Instantly share code, notes, and snippets.

@lopesivan
Last active April 16, 2022 01:48
Show Gist options
  • Save lopesivan/96ca307ad77cbaccee11457f18f33833 to your computer and use it in GitHub Desktop.
Save lopesivan/96ca307ad77cbaccee11457f18f33833 to your computer and use it in GitHub Desktop.
Hello World orientado a objetos em VimScript

Em Vim Script

 1 " metodos
 2 """""""""
 3 
 4 function helloWorld#Show() dict
 5       echo s:message
 6 endfunction
 7 
 8 function helloWorld#Get() dict
 9         call self.Show()
10 endfunction
11 
12 function helloWorld#Set(message) dict
13         let s:message = a:message
14 endfunction
15 
16 
17 " Costrutor
18 """""""""""
19 
20 function helloWorld#New(message)
21 
22         let s:message = a:message
23 
24         let Retval = {
25                         \ 'message': s:message,
26                         \ 'Set'    : function ('helloWorld#Set'),
27                         \ 'Get'    : function ('helloWorld#Get'),
28                         \ 'Show'   : function ('helloWorld#Show')
29         \}
30 
31         return Retval
32 
33 endfunction helloWorld#New

Usando:

$ cat usaHelloWorld.vim
let obj = helloWorld#New("Hello World")

echo "mensagem:" obj.message
echo "obj.Get:" | call obj.Get()
call obj.Set ("Ola Mundo!")
echo "obj.Get:" | call obj.Get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment