Quizás este sea un buen momento para hablar del ri. El comando "ri" es un comando que nos permite tener información sobre un objeto, o sus métodos. Por ejemplo, si hacemos un ri del objeto String (pronto veremos el significado de mayúsculas:
[fecho@sigil ~]$ ri String
Nos dará lo siguiente:
---------------------------------------------------------- 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#[]=+.
------------------------------------------------------------------------
Enhance the String class with a XML escaped character version of
to_s.
------------------------------------------------------------------------
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,
group_by, include?, index_by, inject, map, max, member?, min,
partition, reject, select, sort, sort_by, sum, to_a, to_set, zip)
Constants:
----------
DeletePatternCache: {}
HashCache: {}
PATTERN_EUC: '[\xa1-\xfe][\xa1-\xfe]'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!, 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
(END)
Cómo podemos ver, esto es todas las características del objeto, mientras que si buscamos por ejemplo las características del método length, aplicado al string mediante el siguiente comando:
[fecho@sigil ~]$ ri String#length---------------------------------------------------------- String#length
str.length => integer
------------------------------------------------------------------------
Returns the length of _str_.
(END)
Esto es, lo que el comando hace.
De esta forma podemos obtener información de cualquier objeto y/o método.
En la próxima entrega seguiremos jugando con los strings.
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario