Tbpgr Blog

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

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

Ruby | Module | protected_method_defined?

概要 Module#protected_method_defined?(name) -> bool 詳細 インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が protected であるときに true を返却。 そうでなければ false を返却。 サンプルコード require 'tbpgr_utils' mo…

Ruby | Module | protected_instance_methods

概要 Module#protected_instance_methods(inherited_too = true) -> [Symbol] 詳細 そのモジュールで定義されている protected メソッド名 の一覧を配列で返却。 サンプルコード require 'tbpgr_utils' module Hogeable def hogeable end protected def prot…

Ruby | Module | private_method_defined?

概要 Module#private_method_defined?(name) -> bool 詳細 インスタンスメソッド name がモジュールに定義されており、 しかもその可視性が private であるときに true を返却。 そうでなければ false を返却。 サンプルコード require 'tbpgr_utils' module…

Ruby | Module | private_instance_methods

概要 Module#private_instance_methods(inherited_too = true) -> [Symbol] 詳細 そのモジュールで定義されている private メソッド名 の一覧を配列で返却。 inherited_too によって、継承元のメソッド名も取得するか変更可能。 サンプルコード require 'tbp…

Ruby | Module | name

概要 Module#name -> String Module#to_s -> String Module#inspect -> String 詳細 モジュールやクラスの名前を文字列で返却 サンプルコード require 'tbpgr_utils' module Hogeable def hogeable end end class Hoge include Hogeable def hoge print 'hog…

Ruby | Module | module_exec/class_exec

概要 Module#module_exec(*args) {|*vars| ... } -> object[permalink][rdoc] Module#class_exec(*args) {|*vars| ... } -> object 詳細 与えられたブロックを指定された args を引数としてモジュールのコンテキストで評価する。 サンプルコード module Hoge…

CodeIQ | 『第6回デスマコロシアム』問題 QA @tbpgr #CodeIQ

概要 『第6回デスマコロシアム』問題 QA 詳細 『第6回デスマコロシアム』問題 QAです。 Q1 Q 解答コードの文字数はどのように数えますか?A Byteではなく文字数で数えます。 具体的にはRubyのsizeメソッドで数えます。 Q2 Q ideoneで実行すると、標準出力は…

CodeIQ | 『第6回デスマコロシアム』問題 集計報告 @tbpgr #CodeIQ

概要 『第6回デスマコロシアム』問題 詳細 『第6回デスマコロシアム』問題 の参加状況集計です。 https://codeiq.jp/ace/tbpgr_colosseum_manager/q1027 残言語 挑戦者0名の言語は以下です。 Assembler (gcc-4.8.1) Assembler (nasm-2.10.01) AWK (mawk) bc …

CodeIQ | 『第6回デスマコロシアム』問題 @tbpgr #CodeIQ

概要 『第6回デスマコロシアム』問題 詳細 『第6回デスマコロシアム』問題 の出題を2014年08月26日 AM8:00時から9月16日 AM10時まで行っています。 https://codeiq.jp/ace/tbpgr_colosseum_manager/q1027 どんな問題? 簡単な問題に好きな言語(ideoneの範囲…

Ruby | Module | module_eval/class_eval

概要 Module#module_eval(expr, fname = "(eval)", lineno = 1) -> object[permalink][rdoc] Module#module_eval {|mod| ... } -> object Module#class_eval(expr, fname = "(eval)", lineno = 1) -> object Module#class_eval {|mod| ... } -> object 詳細 …

Ruby | Module | method_defined?

概要 Module#method_defined?(name) -> bool 詳細 モジュールにインスタンスメソッド name が定義されているとき true を返却。 引数は Symbol か String を指定可能 サンプルコード require 'tbpgr_utils' module Hogeable def hogeable end end class Hoge…

Ruby | Module | instance_methods

概要 Module#instance_methods(inherited_too = true) -> [Symbol] 詳細 そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返却。 サンプルコード require 'tbpgr_utils' module Hogeable def hogeable end end class Hoge…

Ruby | Module | instance_method

概要 Module#instance_method(name) -> UnboundMethod 詳細 self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返却。 サンプルコード class Hoge def hoge print 'hoge' end end hoge_method = Hoge.instance_method :hoge puts hoge…

Ruby | Module | included_modules

概要 Module#included_modules -> [Module] 詳細 self にインクルードされているモジュールの配列を返却。 サンプルコード require 'tbpgr_utils' module Hogeable;end module Higeable;end class Hoge include Hogeable include Higeable end class Hige en…

Ruby | Module | include?

概要 include?(mod) -> bool 詳細 self かその親クラス / 親モジュールがモジュール mod を インクルードしていれば true を返却。 サンプルコード require 'tbpgr_utils' module Hogeable;end class Hoge include Hogeable end class Hige end bulk_puts_ev…

Ruby | Module | constants

概要 constants(inherit = true) -> [Symbol] 詳細 そのモジュール(またはクラス)で定義されている定数名の配列を返却。 サンプルコード class Hoge def self.const_missing(id) puts "@@@" Hoge.constants(id, 'dummy value') Hoge.const_get(id) end end #…

Ruby | Module | const_set

概要 const_set(name, value) -> object 詳細 モジュールに name で指定された名前の定数を value とい う値として定義し、value を返却。 定数が定義済みの場合は警告を返却。 サンプルコード class Hoge def self.const_missing(id) puts "@@@" Hoge.const…

Ruby | Module | const_missing

概要 Module#const_missing(name) 詳細 定義されていない定数を参照したときに Ruby インタプリタが呼び出すフックメソッド。 サンプルコード class Hoge def self.const_missing(id) puts "@@@" Hoge.const_set(id, 'dummy value') Hoge.const_get(id) end …

Ruby | Module | const_get

概要 Module#const_get(name, inherit = true) -> object 詳細 name で指定される名前の定数の値を返却する。 サンプルコード require 'tbpgr_utils' module Hogeable HOGEABLE = :hogeable end class Hoge HOGE = :hoge end class ChildHoge < Hoge include…

CodeIQ | 『技術者の会話』問題 @tbpgr #CodeIQ

概要 『技術者の会話』問題 詳細 『技術者の会話』問題 を2014/07/14〜2014/08/06まで出題します。 https://codeiq.jp/ace/tbpgr/q943 どんな問題? 技術者の会話の中に登場する用語を選択式で解答する問題。 経過情報 日次 総人数 全問正解者数 2014/08/06 …

Ruby | Module | const_defined?

概要 Module#const_defined?(name, inherit = true) -> bool 詳細 モジュールに name で指定される名前の定数が定義されていれば true を返却します inherit の値によって継承元も含んで判定するか動作を決めることができる。 サンプルコード require 'tbpgr…

Ruby | Module | class_variables

概要 Module#class_variables -> [Symbol] 詳細 クラス/モジュールに定義されているクラス変数の名前の配列を返却。 サンプルコード require 'tbpgr_utils' module Hogeable @@hoge = 1 end class Hoge @@hoge = 2 end class Hige @@hige = 3 include Hogea…

Ruby | Module | class_variable_set

概要 Module#class_variable_set(name, val) -> object 詳細 クラス/モジュールに定義されているクラス変数 name の値を設定。 サンプルコード require 'tbpgr_utils' module Hogeable @@hoge = 1 end class Hoge @@hoge = 2 end class Hige include Hogeab…

Ruby | Module | class_variable_get

概要 Module#class_variable_get(name) -> bool 詳細 クラス/モジュールに定義されているクラス変数 name の値を返却。 サンプルコード require 'tbpgr_utils' module Hogeable @@hoge = 1 end class Hoge @@hoge = 2 end class Hige include Hogeable end …

Ruby | Module | class_variable_defined?

概要 Module#class_variable_defined?(name) -> bool 詳細 name で与えられた名前のクラス変数が存在する場合 true を 返却。 サンプルコード require 'tbpgr_utils' module Hogeable @@hoge = 1 end class Hoge @@hoge = 2 end class Hige include Hogeable…

Ruby | Module | autoload?

概要 Module#autoload?(const_name) -> String | nil 詳細 const_name が load されていれば nil を、 されていなければ パス を返却します。 サンプルコード 読み込み対象(./target.rb) class Loaded def self.say "loaded!" end end require 'tbpgr_utils'…

Ruby | Module | autoload

概要 Module#autoload(const_name, feature) -> nil 詳細 定数 const_name を参照した際に feature の require を行う サンプルコード 読み込み対象(./target.rb) class Loaded def self.say "loaded!" end end require 'tbpgr_utils' bulk_puts_eval bindin…

Ruby | Module | ancestors

概要 Module#ancestors -> [Class, Module] 詳細 スーパークラス、インクルードモジュールを優先度順に配列で取得する。 サンプルコード require 'tbpgr_utils' module ParentModule end class ImplModuleClass include ParentModule end class ExtendedClas…

Ruby | Module | >=

概要 Module#>= other -> bool | nil 詳細 比較演算子。self が other の先祖であるか同一クラスである場合、 true を返却 self が other の子孫のクラス/モジュールの場合、 false を返却 継承関係にないクラス同士の比較では nil を返却 サンプルコード r…

Ruby | Module | >

概要 Module#> other -> bool | nil 詳細 比較演算子。self が other の先祖である場合、 true を返却 self が other の子孫か同一のクラス/モジュールの場合、 false を返却 継承関係にないクラス同士の比較では nil を返却 サンプルコード require 'tbpgr…