種類
- インスタンスメソッド (561)
- 特異メソッド (77)
- モジュール関数 (22)
- クラス (11)
ライブラリ
- ビルトイン (671)
クラス
-
ARGF
. class (9) - Binding (11)
-
Encoding
:: Converter (44) - IO (11)
- Module (201)
- Object (143)
- Proc (13)
- String (30)
- Struct (44)
- Symbol (77)
- Thread (22)
- TracePoint (11)
キーワード
- == (11)
- [] (11)
- attr (33)
- casecmp? (8)
-
class
_ variable _ defined? (11) -
class
_ variables (11) - clone (11)
-
const
_ defined? (11) -
const
_ get (11) -
const
_ source _ location (5) - constants (11)
-
deprecate
_ constant (5) - dup (11)
- empty? (11)
-
end
_ with? (5) - equal? (11)
- hash (11)
- id2name (11)
-
instance
_ methods (11) -
instance
_ variable _ defined? (11) - intern (11)
- key? (11)
-
latest
_ gc _ info (22) -
local
_ variable _ defined? (11) - match? (16)
-
method
_ defined? (11) - methods (11)
- name (4)
- new (33)
-
object
_ id (11) - parameters (2)
-
primitive
_ convert (44) -
private
_ class _ method (15) -
private
_ instance _ methods (11) -
private
_ method _ defined? (11) -
private
_ methods (11) -
protected
_ instance _ methods (11) -
protected
_ method _ defined? (11) -
protected
_ methods (11) -
public
_ instance _ methods (11) -
public
_ method _ defined? (11) -
public
_ methods (11) -
read
_ nonblock (20) -
respond
_ to? (11) -
respond
_ to _ missing? (11) -
singleton
_ class (11) -
singleton
_ methods (11) -
start
_ with? (5) -
thread
_ variable? (11) -
to
_ proc (3) -
to
_ s (11) -
to
_ sym (11) - trace (11)
- trap (22)
検索結果
先頭5件
-
Symbol (46048.0)
-
シンボルを表すクラス。シンボルは任意の文字列と一対一に対応するオブジェクトです。
...です。
シンボルオブジェクトは以下のようなリテラルで得られます。
:symbol
:'symbol'
%s!symbol! # %記法
生成されたシンボルの一覧は Symbol.all_symbols で得られます。
一番目のリテラルでシンボルを表す場合、`:' の後に
は......い、immutable (変更不可)であり、同値ならば必ず同一です。
p "abc" == "abc" #=> true
p "abc".equal?("abc") #=> false
p :abc == :abc #=> true
p :abc.equal?(:abc) #=> true ←同値ならば同一
==== 用途
実用面では、シンボルは文字の意味を明確にし......配がない
大抵のメソッドはシンボルの代わりに文字列を引数として渡すこともできるようになっています。
Symbol クラスのメソッドには、String クラスのメソッドと同名で似た働きをするものもあります。
==== GC
内部的に... -
Symbol
# ==(other) -> true | false (29107.0) -
other が同じシンボルの時に真を返します。 そうでない場合は偽を返します。
...other が同じシンボルの時に真を返します。
そうでない場合は偽を返します。
@param other 比較対象のシンボルを指定します。
例:
:aaa == :aaa #=> true
:aaa == :xxx #=> false... -
Symbol
# start _ with?(*prefixes) -> bool (29046.0) -
self の先頭が prefixes のいずれかであるとき true を返します。
...であるとき true を返します。
(self.to_s.start_with?と同じです。)
@param prefixes パターンを表す文字列または正規表現 (のリスト)
@see Symbol#end_with?
@see String#start_with?
//emlist[][ruby]{
:hello.start_with?("hell") #=> true
:hello.start_wit......h?(/H/i) #=> true
# returns true if one of the prefixes matches.
:hello.start_with?("heaven", "hell") #=> true
:hello.start_with?("heaven", "paradise") #=> false
//}... -
Symbol
# casecmp?(other) -> bool | nil (29040.0) -
大文字小文字の違いを無視しシンボルを比較します。 シンボルが一致する場合には true を返し、一致しない場合には false を返します。
...ンボルが一致する場合には true を返し、一致しない場合には false を返します。
@param other 比較対象のシンボルを指定します。
//emlist[][ruby]{
:abcdef.casecmp?(:abcde) #=> false
:aBcDeF.casecmp?(:abcdef) #=> true
:abcdef.casecmp?(:abcdefg) #=> f......alse
:abcdef.casecmp?(:ABCDEF) #=> true
:"\u{e4 f6 fc}".casecmp?(:"\u{c4 d6 dc}") #=> true
//}
other がシンボルではない場合や、文字列のエンコーディングが非互換の場合は、nil を返します。
//emlist[][ruby]{
:foo.casecmp?("foo") #=> nil
"\u{e4 f6 fc}".encod......e("ISO-8859-1").to_sym.casecmp?(:"\u{c4 d6 dc}") #=> nil
//}
@see String#casecmp?, Symbol#casecmp... -
Symbol
# end _ with?(*suffixes) -> bool (29040.0) -
self の末尾が suffixes のいずれかであるとき true を返します。
...れかであるとき true を返します。
(self.to_s.end_with?と同じです。)
@param suffixes パターンを表す文字列 (のリスト)
@see Symbol#start_with?
@see String#end_with?
//emlist[][ruby]{
:hello.end_with?("ello") #=> true
# returns true if one of the +suff......ixes+ matches.
:hello.end_with?("heaven", "ello") #=> true
:hello.end_with?("heaven", "paradise") #=> false
//}... -
Symbol
# match?(regexp , pos = 0) -> bool (29018.0) -
regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。
...しくは Regexp#match? を参照してください。
例:
:Ruby.match?(/R.../) # => true
:Ruby.match?('Ruby') # => true
:Ruby.match?('Ruby',1) # => false
:Ruby.match?('uby',1) # => true
:Ruby.match?(/P.../) # => false
$& # => nil
@see Regexp#match?,... -
Symbol
# name -> String (29018.0) -
シンボルに対応する文字列を返します。
...シンボルに対応する文字列を返します。
Symbol#to_sと違って freeze された文字列を返します。
//emlist[][ruby]{
p :fred.name # => "fred"
p :fred.name.frozen? # => true
p :fred.to_s # => "fred"
p :fred.to_s.frozen? # => false
//}
@see Symbol#to_s... -
Symbol
# id2name -> String (29012.0) -
シンボルに対応する文字列を返します。
...シンボルに対応する文字列を返します。
逆に、文字列に対応するシンボルを得るには
String#intern を使います。
p :foo.id2name # => "foo"
p :foo.id2name.intern == :foo # => true
@see String#intern
@see Symbol#name... -
Symbol
# to _ s -> String (29012.0) -
シンボルに対応する文字列を返します。
...シンボルに対応する文字列を返します。
逆に、文字列に対応するシンボルを得るには
String#intern を使います。
p :foo.id2name # => "foo"
p :foo.id2name.intern == :foo # => true
@see String#intern
@see Symbol#name... -
Symbol
# empty? -> bool (29006.0) -
自身が :"" (length が 0 のシンボル)かどうかを返します。
...自身が :"" (length が 0 のシンボル)かどうかを返します。
:"".empty? #=> true
:foo.empty? #=> false
@see String#empty?... -
Symbol
# id2name -> String (29006.0) -
シンボルに対応する文字列を返します。
...シンボルに対応する文字列を返します。
逆に、文字列に対応するシンボルを得るには
String#intern を使います。
p :foo.id2name # => "foo"
p :foo.id2name.intern == :foo # => true
@see String#intern... -
Symbol
# to _ proc -> Proc (29006.0) -
self に対応する Proc オブジェクトを返します。
...数を渡して呼びだします。
生成される Proc オブジェクトは lambda です。
//emlist[][ruby]{
:object_id.to_proc.lambda? # => true
//}
//emlist[明示的に呼ぶ例][ruby]{
:to_i.to_proc["ff", 16] # => 255 ← "ff".to_i(16)と同じ
//}
//emlist[暗黙に呼ばれる例][ru... -
Symbol
# to _ s -> String (29006.0) -
シンボルに対応する文字列を返します。
...シンボルに対応する文字列を返します。
逆に、文字列に対応するシンボルを得るには
String#intern を使います。
p :foo.id2name # => "foo"
p :foo.id2name.intern == :foo # => true
@see String#intern... -
Module
# instance _ methods(inherited _ too = true) -> [Symbol] (8256.0) -
そのモジュールで定義されている public および protected メソッド名 の一覧を配列で返します。
... true を指定して
# いるが、Object のインスタンスメソッドは一覧から排除している。
p Bar.instance_methods(true) - Object.instance_methods(true)
p Bar.public_instance_methods(true) - Object.public_instance_methods(true)
p Bar.private_instance_methods(true)......- Object.private_instance_methods(true)
p Bar.protected_instance_methods(true) - Object.protected_instance_methods(true)
//}
実行結果
[:protected_foo, :public_foo]
[:public_foo]
[:private_foo]
[:protected_foo]... -
Object
# methods(include _ inherited = true) -> [Symbol] (8256.0) -
そのオブジェクトに対して呼び出せるメソッド名の一覧を返します。 このメソッドは public メソッドおよび protected メソッドの名前を返します。
...めるために true を指定して
# いるが、Object のインスタンスメソッドは一覧から排除している。
p obj.methods(true) - Object.instance_methods(true)
p obj.public_methods(true) - Object.public_instance_methods(true)
p obj.private_methods(true) - Object.pr......ivate_instance_methods(true)
p obj.protected_methods(true) - Object.protected_instance_methods(true)
# 実行結果
[:protected_singleton, :public_singleton, :protected_foo, :public_foo, :protected_parent, :public_parent]
[:public_singleton, :public_foo, :public_parent]
[:private_singleton, :privat...