This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: UTF-8 | |
| class Logger | |
| def self.write(out, log) | |
| out.write log | |
| end | |
| end | |
| File.open("hoge", "w") do |f| | |
| Logger.write(f, "log") # ファイルに書き込み |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: UTF-8 | |
| class Logger | |
| def self.write(out, log) | |
| raise TypeError, "書き込めない何かだよ" unless out.respond_to? :write | |
| out.write log | |
| end | |
| end | |
| File.open("hoge", "w") do |f| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: UTF-8 | |
| class Logger | |
| def self.write(out, log) | |
| out.write log | |
| rescue | |
| raise TypeError, "書き込めない何かだよ" | |
| end | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| def profile(msg, &block) | |
| start_time = Time.now | |
| yield | |
| duration = Time.now - start_time | |
| puts msg << ": " << duration.to_s << "秒" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: UTF-8 | |
| def counter_closer | |
| count = 0 | |
| lambda{|n| count += n} | |
| end | |
| counter = counter_closer | |
| puts counter.call(1) | |
| puts counter.call(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Railsで確認画面を実装するときのテンプレ | |
| # | |
| def confirm | |
| if request.post? | |
| @entry = Entry.new(params[:entry]) | |
| else request.put? | |
| @entry = Entry.find(params[:id]) | |
| @entry.attributes = params[:entry] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function! Fib(arg) | |
| if a:arg == 0 | |
| return 0 | |
| elseif a:arg == 1 || a:arg == 2 | |
| return 1 | |
| else | |
| return Fib(a:arg - 1) + Fib(a:arg - 2) | |
| endif | |
| endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let s:id_counter = 0 | |
| let s:klass = {'_class_': ['Klass'], '_id_': 0} | |
| " クラスの作成 | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby << EOF | |
| class Person | |
| attr_accessor :name, :age | |
| def initialize(name, age) | |
| @name = name | |
| @age = age | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ruby << EOF | |
| class Person | |
| attr_accessor :name, :age | |
| def initialize(name, age) | |
| @name = name | |
| @age = age | |
| end | |
| end |