Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

2014-10-01から1ヶ月間の記事一覧

Ruby | Proc | to_proc

概要 Proc#to_proc -> self 詳細 自身を返却。 Duck Typing 用か? サンプルコード require 'tbpgr_utils' p1 = Proc.new {} p2 = proc {} p3 = lambda {} class Sum def sum(a, b) a + b end def to_proc -> (a, b) {a + b} end end def use_proc(a, b, pr)…

Ruby | Proc | source_location

概要 Proc#source_location -> [String, Fixnum] | nil 詳細 Procを定義したソースコードのファイル名と行番号を配列で返却。 サンプルコード require 'tbpgr_utils' pr1 = Proc.new {} pr2 = proc {} lm = lambda {} bulk_puts_eval binding, <<-EOS pr1.so…

Ruby | Proc | lambda?

概要 Proc#lambda? -> bool 詳細 手続きオブジェクトの引数の取扱が厳密であるならば true を返却。 サンプルコード require 'tbpgr_utils' def hoge(&b) b.lambda? end def hige;;end bulk_puts_eval binding, <<-EOS lambda {}.lambda? Proc.new {}.lambda…

Ruby | Proc | curry

概要 Proc#curry 詳細 Procをカリー化する。カリー化を利用すると、1引数をとる高階関数に複数の引数を持つ関数を渡せる。下記の記事が非常に参考になる。 「関数型Ruby」という病(3) - カリー化(Proc#curry, Proc#flip) http://yuroyoro.hatenablog.com/ent…

Impact Mapping | プロジェクトとプロダクトに大きなインパクトを与える Impact Mapping ってなんぞ?

プロジェクトとプロダクトに大きなインパクトを与える Impact Mapping という手法について。 Impact Mapping とは? Impact Mapping はマインドマップを利用した戦略的計画技法の一つです。この手法は、 ・明確な仮定を作り、伝達する ・ビジネスに関わるチ…

Ruby | Proc | arity

概要 Proc#arity 詳細 Proc オブジェクトが受け付ける引数の数を返却。 可変長の場合は必要とされる引数の数 + 1 を負の値にして返却。 サンプルコード require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS Proc.new { || }.arity Proc.new { |x|x }.arit…

Ruby | Proc | []

概要 Proc#self[*arg] -> () Proc#call(*arg) -> () Proc#self === *arg -> () Proc#yield(*arg) -> () 詳細 手続きオブジェクトを実行してその結果を返却。 「 === 」 は case 文での利用のため。 サンプルコード require 'tbpgr_utils' pr = Proc.new { |m…

Ruby | Proc | new

概要 Proc.new -> Proc Proc.new { ... } -> Proc 詳細 ブロックをコンテキストとともにオブジェクト化して返却。 ブロックを指定しない場合は、このメソッドを呼び出したメソッドが ブロックを伴う場合に、Procを生成。 サンプルコード require 'tbpgr_util…

Ruby | ObjectSpace | undefine_finalizer

概要 Object#undefine_finalizer(obj) -> object 詳細 define_finalizer で登録した obj が解放されるときに実行されるファイナライザ proc の登録をすべて解除する。 サンプルコード class Hoge def Hoge.callback proc { puts "finalize" } end def initia…

Ruby | ObjectSpace | garbage_collect

概要 ObjectSpace#garbage_collect(full_mark: true, immediate_sweep: true) -> nil 詳細 参照されなくなったオブジェクトを回収する。 GC.start と同じ。 サンプルコード require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS GC.count ObjectSpace.garb…

Ruby | ObjectSpace | each_object

概要 ObjectSpace#each_object {|object| ...} -> Integer ObjectSpace#each_object(klass) {|object| ...} -> Integer ObjectSpace#each_object -> Enumerator ObjectSpace#each_object(klass) -> Enumerator 詳細 指定された klass と Object#kind_of? の…

Ruby | ObjectSpace | define_finalizer

概要 ObjectSpace#define_finalizer(obj, proc) -> Array ObjectSpace#define_finalizer(obj) {|id| ...} -> Array 詳細 obj が解放されるときに実行されるファイナライザ proc を 登録。 同一オブジェクトへの設定は追加になる。 サンプルコード class Hoge…

Ruby | ObjectSpace | count_objects

概要 ObjectSpace#count_objects(result_hash = {}) -> Hash 詳細 オブジェクトを種類ごとにカウントした結果を Hash として返却。 サンプルコード require 'tbpgr_utils' hash = {} bulk_puts_eval binding, <<-EOS ObjectSpace.count_objects class Hoge; …

Ruby | ObjectSpace | _id2ref

概要 ObjectSpace#_id2ref(id) -> object 詳細 オブジェクト ID(Object#__id__)からオブジェクトを取得 サンプルコード require 'tbpgr_utils' Person = Struct.new(:name, :age) tanaka = Person.new('tanaka', 34) hoge = "hoge" bulk_puts_eval binding, <…

Ruby | Object | remove_instance_variable

概要 Object#remove_instance_variable(name) -> object 詳細 オブジェクトからインスタンス変数 name を削除。 そのインスタンス変数に設定されていた値を返却。 サンプルコード require 'tbpgr_utils' class Person attr_reader :name, :age def initializ…

Ruby | Object | initialize

概要 Object#initialize(*args, &block) -> object 詳細 ユーザ定義クラスのオブジェクト初期化メソッド。 new から呼び出される処理で、 new に渡された引数をそのまま引き継ぐ。 ユーザーが作成するクラスで再定義されることを期待されている。 サンプルコ…

Ruby | Object | untrusted?

概要 Object#untrusted? -> bool 詳細 オブジェクトに「untrustマーク」がついていたら真を返却する サンプルコード require 'tbpgr_utils' Person = Struct.new(:name, :age) tanaka = Person.new('tanaka', 24) bulk_puts_eval binding, <<-EOS tanaka.nam…

Ruby | Object | untaint

概要 Object#untaint -> self 詳細 オブジェクトの汚染マークを除去する。セキュリティレベルについては下記参照。 http://docs.ruby-lang.org/ja/2.1.0/doc/spec=2fsafelevel.html サンプルコード require 'tbpgr_utils' name = ARGV[0] age = ARGV[1] Pers…

Ruby | Object | trust

概要 Object#trust -> self 詳細 オブジェクトの「untrustマーク」を除去。 サンプルコード require 'tbpgr_utils' Person = Struct.new(:name, :age) tanaka = Person.new('tanaka', 24) bulk_puts_eval binding, <<-EOS tanaka.name.untrusted? tanaka.nam…

Ruby | Object | to_s

概要 Object#to_s -> String 詳細 オブジェクトの文字列表現を返却。 Kernel.#print や 文字列の変数展開などの際に呼び出される。 サンプルコード Person = Struct.new(:name, :age) tanaka = Person.new('tanaka', 34) print tanaka.to_s, "\n" print "#{t…

Ruby | Object | tap

概要 Object#tap {|x| ... } -> self 詳細 self を引数としてブロックを評価し、self を返却。 メソッドチェインの途中に割り込んで、処理途中の値を表示・確認するのが目的。 サンプルコード p [*1..5].zip([*?a..?e]).tap { |e|print e.inspect, "\n"} .ma…

Ruby | Object | tainted?

概要 Object#tainted? -> bool 詳細 オブジェクトの「汚染マーク」がセットされている時真を返却。 オブジェクトの「汚染マーク」は、組み込み機能利用時に内部で設定される場合と、 自分で Object#taint / untaint メソッドで設定する場合がある。セキュリ…

CodeIQ | 『PIの中にRaspberryはいくつ』問題 @tbpgr #CodeIQ

概要 『PIの中にRaspberryはいくつ』問題 詳細 『PIの中にRaspberryはいくつ』問題 を2014/10/10〜2014/11/04まで出題します。 https://codeiq.jp/ace/tbpgr/q1056 どんな問題? PIの中にあるRaspberryを数える問題です。 正解者の中から抽選で1名様に Raspb…

Ruby | Object | taint

概要 Object#taint -> self 詳細 オブジェクトの汚染マークを設定する。セキュリティレベルについては下記参照。 http://docs.ruby-lang.org/ja/2.1.0/doc/spec=2fsafelevel.html サンプルコード require 'tbpgr_utils' name = ARGV[0] age = ARGV[1] Person…

Ruby | Object | singleton_methods

概要 Object#singleton_methods(inherited_too = true) -> [Symbol] 詳細 そのオブジェクトに対して定義されている特異メソッド名 (public あるいは protected メソッド) の一覧を返却。 inherited_too が true の場合、継承したメソッドも含む。 サンプルコ…

GitHub | ユーザーページの作り方

概要 ユーザーページの作り方 詳細 GitHubでは、 [user_name].github.com という名前のリポジトリを作成すると、 [user_name].github.io という静的サイトとして公開されます。例えば私なら、tbpgr.github.com というリポジトリが http://tbpgr.github.io/ …

Ruby | Object | send

概要 Object#send(name, *args) -> object Object#send(name, *args) { .... } -> object Object#__send__(name, *args) -> object Object#__send__(name, *args) { .... } -> object 詳細 オブジェクトのメソッド name を args を引数に して呼び出し、メソ…

Ruby | Object | respond_to?

概要 Object#respond_to?(name, include_all = false) -> bool 詳細 オブジェクトがメソッド name を持つとき真を返却 NotImplementedError が発生する場合は真を返却NotImplementedError の場合に偽を返すようになった経緯については下記を参照。 http://co…

Ruby | Object | public_send

概要 Object#public_send(name, *args) -> object 詳細 オブジェクトの public メソッド name を args を引数にして呼び出し、メソッ ドの実行結果を返却。 send とは異なり、 public メソッドのみを対象とする。 サンプルコード class Hoge def public_hoge…

Ruby | Object | public_methods

概要 Object#public_methods(include_inherited = true) -> [Symbol] 詳細 publicメソッド名の一覧を返却。 include_inherited に false を指定すると自クラスのメソッドのみを返却 サンプルコード require 'tbpgr_utils' module Mod def mod; end end class…