|
|
||
---------------------------------------------------------- Class: String A String object holds and manipulates an arbitrary sequence of bytes, typically representing characters. String objects may be created using String::new or as literals. Because of aliasing issues, users of strings should be aware of the methods that modify the contents of a String object. Typically, methods with names ending in ``!'' modify their receiver, while those without a ``!'' return a new String . However, there are exceptions, such as String#[]= . ------------------------------------------------------------------------ Includes: --------- Comparable(<, <=, ==, >, >=, between?), Enumerable(all?, any?, collect, detect, each_cons, each_slice, each_with_index, entries, enum_cons, enum_slice, enum_with_index, find, find_all, grep, include?, inject, map, max, member?, min, partition, reject, select, sort, sort_by, to_a, to_set, zip) Class methods: -------------- new Instance methods: ----------------- %, *, , <<, <=>, ==, =~, , =, capitalize, capitalize!, casecmp, center, chomp, chomp!, chop, chop!, concat, count, crypt, delete, delete!, downcase, downcase!, dump, each, each_byte, each_line, empty?, eql?, gsub, gsub!, hash, hex, include?, index, initialize_copy, insert, inspect, intern, length, ljust, lstrip, lstrip!, match, next, next!, oct, replace, reverse, reverse!, rindex, rjust, rstrip, rstrip!, scan, size, slice, slice!, split, squeeze, squeeze!, strip, strip!, sub, sub!, succ, succ!, sum, swapcase, swapcase!, to_f, to_i, to_s, to_str, to_sym, tr, tr!, tr_s, tr_s!, unpack, upcase, upcase!, upto
==== String ==== 文字列クラス。任意の長さのバイト列を扱うことができます。 このクラスのメソッドのうち名前が ! で終るものは文字列の中身を 直接変更します。このような場合は ! のついていない同じ名前の メソッドを使うほうが概して安全です。たとえば以下のような場合に問題に なることがあります。 def foo(arg) arg.sub!(/good/, 'bad') arg end s = 'verygoodname' p foo(s) # => 'verybadname' p s # => 'verybadname' また日本語文字列を正しく処理するためには組み込み変数 $KCODE を 文字コードにあわせて設定しておく必要があります。 String クラスは自身をバイト列として扱います。例えば str[1] は str の内 容がなんであれ 2 バイト目の文字コードを返します。日本語文字列に対して (バイト単位でなく)文字単位の処理を行わせたい場合は jcode.rb を使 用します。 ---- Singleton methods ---- new ---- Instance methods ---- % * < << <= <=> == =~ > >= = capitalize capitalize! casecmp center chomp chomp! chop chop! clone concat count crypt delete delete! downcase downcase! dump dup each each_byte each_line empty? external_filter gsub gsub! hex include? index insert intern length ljust lstrip lstrip! match next next! oct replace reverse reverse! rindex rjust rstrip rstrip! scan size slice slice! split squeeze squeeze! strip strip! sub sub! succ succ! sum swapcase swapcase! to_f to_i to_s to_str to_sym tr tr! tr_s tr_s! unpack upcase upcase! upto ~ ---- Singleton methods (inherited) ---- ---- Instance methods (inherited) ---- === __id__ __send__ _dump _load all? any? between? class collect detect display each_with_index entries eql? equal? extend find find_all freeze frozen? grep hash id initialize initialize_copy inject inspect instance_eval instance_of? instance_variable_get instance_variable_set instance_variables is_a? kind_of? map marshal_dump marshal_load max member? method method_missing methods min nil? object_id partition pretty_print pretty_print_cycle pretty_print_instance_variables private_methods protected_methods public_methods reject remove_instance_variable respond_to? select send singleton_method_added singleton_method_removed singleton_method_undefined singleton_methods sort sort_by taint tainted? to_a to_ary to_hash to_int type untaint zip
* はてなダイアリーキーワード:String