vim de oop

40
Vim Script De OOP 株式会社RAWHIDE. 赤松 祐希(id:ukstudio)

Upload: yuki-akamatsu

Post on 13-Jul-2015

883 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Vim DE OOP

Vim Script De OOP

株式会社RAWHIDE.赤松 祐希(id:ukstudio)

Page 2: Vim DE OOP

自己紹介

Page 3: Vim DE OOP

宣伝

Page 4: Vim DE OOP

http://vim-users.jp

Lingrもあるよhttp://www.lingr.com/room/vim-users.jp

Page 5: Vim DE OOP

Vim Script書いたことない人?(́・ω・`)ノシ

Page 6: Vim DE OOP

:help script

Page 7: Vim DE OOP

Vimで書いてVimで実行してVimでデバッグしてVimで調べられる

Page 8: Vim DE OOP

ここからOOPの話

Page 9: Vim DE OOP

クラス定義

Page 10: Vim DE OOP

" クラス定義 let Person = s:klass.create({ \ '_class_': ['Person'], \ 'name': '', \ 'age' : 0})

Page 11: Vim DE OOP

ちょっとダサい・・・

Page 12: Vim DE OOP

メソッド定義

Page 13: Vim DE OOP

" メソッド定義 function! Person.hello() echo "Hello! My name is" self.name endfunction

let ukstudio = Person.new({'name': 'ukstudio', 'age': 22}) echo ukstudio call ukstudio.hello() “ Hello! My name is ukstudio

let tarou = Person.new({'name': 'tarou', 'age': 34}) call tarou.hello() “Hello! My name is tarou

Page 14: Vim DE OOP

メソッド一覧

Page 15: Vim DE OOP

"メソッドの一覧 echo ukstudio.methods() “ ['hello', 'extend', 'methods', 'is_a', 'new']

Page 16: Vim DE OOP

継承

Page 17: Vim DE OOP

"継承する let Member = Person.extend({'_class_':'Member'}) let member = Member.new({'name': 'member', 'age': 12})

call member.hello() “ Hello! My name is member

"継承関係にあるか echo ukstudio.is_a('Klass') “ 1 echo ukstudio.is_a('Person') “ 1 echo member.is_a('Person') “ 1

Page 18: Vim DE OOP

内部の話

Page 19: Vim DE OOP

http://gist.github.com/89661

サンプルも含めて全部ココ!

Page 20: Vim DE OOP

辞書

Page 21: Vim DE OOP

:help Dictionary

Page 22: Vim DE OOP

辞書の値に関数を渡せる

Page 23: Vim DE OOP

let di = {}

function Hello() echo ‘Hello’endfunction

let di.hello = function(‘Hello’)echo di.hello() “ Hello

Page 24: Vim DE OOP

let di = {}

function di.hello() dict echo ‘Hello’endfunction

echo di.hello()

Page 25: Vim DE OOP

JSのprototypeに似てる

Page 26: Vim DE OOP

ちょっとだけ仕組みの説明

Page 27: Vim DE OOP

" クラスの作成function! s:klass.create(...) dict let object = deepcopy(self) let class = copy(self._class_) for c in get(a:1, '_class_', []) call add(class, c) endfor let s:id_counter += 1 let object._id_ = s:id_counter call remove(object, 'create') call extend(object, a:1) let object._class_ = class return objectendfunction

Page 28: Vim DE OOP

" インスタンスの作成function! s:klass.new(...) dict let object = deepcopy(self) let s:id_counter += 1 let object._id_ = s:id_counter if a:0 >= 1 && !empty(a:1) call extend(object, a:1) endif return objectendfunction

Page 29: Vim DE OOP

let ukstudio = \ Person.new({'name': 'ukstudio', 'age': 22, 'hoge': 'hoge'}) echo ukstudio

{'hello': function('113'), 'age': 22, 'extend': function('112'), 'name': 'ukstudio', '_id_': 2, '_class_': ['Klass', 'Person'], 'methods': function('110'), 'hoge': 'hoge', 'is_a': function('111'), 'new': function('109')}

Page 30: Vim DE OOP

OOPの必要性

Page 31: Vim DE OOP

多分いらない

Page 32: Vim DE OOP

自分の発表全否定w

Page 33: Vim DE OOP

Rails.vimhttp://github.com/tpope/vim-rails/tree/master

Page 34: Vim DE OOP

スクリプトローカルな関数がたくさん

Page 35: Vim DE OOP

こっちの方がわかりやすい

Page 36: Vim DE OOP

それでもOOPがいいあなたへ

Page 37: Vim DE OOP

if_ruby

Page 38: Vim DE OOP

:help if_ruby

Page 39: Vim DE OOP

http://gist.github.com/89679

ruby << EOF class Person attr_accessor :name, :age

def initialize(name, age) @name = name @age = age end end

ukstudio = Person.new("ukstudio", 22) p ukstudio

require 'rubygems' require 'ruby-growl' g = Growl.new("localhost", "ruby-growl", ["ruby-growl Notification"]) g.notify("ruby-growl Notification", "Vim勉強会 in MTL", "発表中") EOF

Page 40: Vim DE OOP

ご静聴ありがとうございました