Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Thursday, December 2, 2010

Investing The Methods Of An Object On Unite

How often do you use Object#methods? That's convenient particularly on IRB.

methods on irb

methods on irb

This is also available on Unite.vim. Write the following code on your ~/.vimrc

let s:unite_source = {
      \ 'name': 'evalruby',
      \ 'is_volatile': 1,
      \ 'required_pattern_length': 1,
      \ 'max_candidates': 30,
      \ }

function! s:unite_source.gather_candidates(args, context)
  if a:context.input[-1:] == '.'
    let methods = split(
          \ unite#util#system(printf('ruby -e "puts %s.methods"', a:context.input[:-2])),
          \ "\n")
    call map(methods, printf("'%s' . v:val", a:context.input))
    let methods = [a:context.input]
  return map(methods, '{
        \ "word": v:val,
        \ "source": "evalruby",
        \ "kind": "command",
        \ "action__command": printf("!ruby -e \"p %s\"", v:val),
        \ }')

call unite#define_source(s:unite_source)

Execute :Unite evalruby on your Vim, and write an expression.



Ruby Advent Calendar jp-en: 2010

This entry is for the event Ruby Advent Calendar jp-en: 2010. The previous post was from yhara and the next post will be from authorNari. I'm sure he will write an entry about GC.

I also had written an entry of the event last year Time flees away without delay.

No comments:

Post a Comment