I am running ruby 1.8.6 patchlevel 111 on Windows XP(same problem with
OS X). I am wondering why each_char doesn’t work for me? I looked at
the documentation and it shows ‘each_char’, however when I look at the
results of class.instance_methods.sort, each_char is nowhere to be
found. Any explanations to why I can’t use it? Thanks
-Juan
---------------------------------------------------------- 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#[]=+.
User defined methods to be added to 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, inject, map, max, member?, min, partition,
reject, select, sort, sort_by, to_a, to_set, zip)
Constants:
DeletePatternCache: {}
HashCache: {}
PATTERN_EUC: '[\xa1-\xfe][\xa1-\xfe]'
PATTERN_SJIS: '[\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc]'
PATTERN_UTF8: '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-
\xbf]
[\x80-\xbf]’
RE_EUC: Regexp.new(PATTERN_EUC, 0, ‘n’)
RE_SJIS: Regexp.new(PATTERN_SJIS, 0, ‘n’)
RE_UTF8: Regexp.new(PATTERN_UTF8, 0, ‘n’)
SUCC: {}
SqueezePatternCache: {}
TrPatternCache: {}
Class methods:
new, yaml_new
Instance methods:
%, *, +, <<, <=>, ==, =~, [], []=, _expand_ch, _regex_quote,
block_scanf, capitalize, capitalize!, casecmp, center, chomp,
chomp!, chop, chop!, concat, count, crypt, delete, delete!,
downcase, downcase!, dump, each, each_byte, each_char, each_line,
empty?, end_regexp, eql?, expand_ch_hash, ext, gsub, gsub!, hash,
hex, include?, index, initialize_copy, insert, inspect, intern,
is_binary_data?, is_complex_yaml?, iseuc, issjis, isutf8, jcount,
jlength, jsize, kconv, length, ljust, lstrip, lstrip!, match,
mbchar?, next, next!, nstrip, oct, original_succ, original_succ!,
pathmap, pathmap_explode, pathmap_partial, pathmap_replace,
quote,
replace, reverse, reverse!, rindex, rjust, rstrip, rstrip!, scan,
scanf, 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, to_yaml, toeuc, tojis, tosjis,
toutf16,
toutf8, tr, tr!, tr_s, tr_s!, unpack, upcase, upcase!, upto
irb
irb(main):001:0> st=“hithere”
=> “hithere”
irb(main):005:0> st.class.each_char{|s| puts s}
NoMethodError: undefined method `each_char’ for String:Class
from (irb):5
from :0
irb(main):011:0> st.class.instance_methods.sort
=> ["%", “*”, “+”, “<”, “<<”, “<=”, “<=>”, “==”, “===”, “=~”, “>”,
“>=”, “[]”, “[]=”, “id”, “send”, “all?”, “any?”, “bet
ween?”, “capitalize”, “capitalize!”, “casecmp”, “center”, “chomp”,
“chomp!”, “chop”, “chop!”, “class”, “clone”, “collect”, “conc
at”, “count”, “crypt”, “delete”, “delete!”, “detect”, “display”,
“downcase”, “downcase!”, “dump”, “dup”, “each”, “each_byte”, “e
ach_line”, “each_with_index”, “empty?”, “entries”, “eql?”, “equal?”,
“extend”, “find”, “find_all”, “freeze”, “frozen?”, “grep”,
“gsub”, “gsub!”, “hash”, “hex”, “id”, “include?”, “index”, “inject”,
“insert”, “inspect”, “instance_eval”, “instance_of?”, “inst
ance_variable_defined?”, “instance_variable_get”,
“instance_variable_set”, “instance_variables”, “intern”, “is_a?”,
“kind_of?”,
“length”, “ljust”, “lstrip”, “lstrip!”, “map”, “match”, “max”,
“member?”, “method”, “methods”, “min”, “next”, “next!”, “nil?”, "
object_id", “oct”, “partition”, “private_methods”,
“protected_methods”, “public_methods”, “reject”, “replace”,
“respond_to?”, “r
everse”, “reverse!”, “rindex”, “rjust”, “rstrip”, “rstrip!”, “scan”,
“select”, “send”, “singleton_methods”, “size”, “slice”, “sl
ice!”, “sort”, “sort_by”, “split”, “squeeze”, “squeeze!”, “strip”,
“strip!”, “sub”, “sub!”, “succ”, “succ!”, “sum”, “swapcase”,
“swapcase!”, “taint”, “tainted?”, “to_a”, “to_f”, “to_i”, “to_s”,
“to_str”, “to_sym”, “tr”, “tr!”, “tr_s”, “tr_s!”, “type”, “unp
ack”, “untaint”, “upcase”, “upcase!”, “upto”, “zip”]
irb(main):012:0>