From 3d60b3617080284ca08fac45412de77ea7750284 Mon Sep 17 00:00:00 2001 From: dave Date: Sat, 27 Dec 2003 06:09:08 +0000 Subject: RDoc comments for Symbol git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5317 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) (limited to 'object.c') diff --git a/object.c b/object.c index 174d8ccfc0..0cd4bf3036 100644 --- a/object.c +++ b/object.c @@ -448,6 +448,24 @@ main_to_s(obj) return rb_str_new2("main"); } + +/*********************************************************************** + * Document-class: TrueClass + * + * The global value true is the only instance of class + * TrueClass and represents a logically true value in + * boolean expressions. The class provides operators allowing + * true to be used in logical expressions. + */ + + +/* + * call-seq: + * true.to_s => "true" + * + * The string representation of true is "true". + */ + static VALUE true_to_s(obj) VALUE obj; @@ -455,6 +473,15 @@ true_to_s(obj) return rb_str_new2("true"); } + +/* + * call-seq: + * true & obj => true or false + * + * And---Returns false if obj is + * nil or false, true otherwise. + */ + static VALUE true_and(obj, obj2) VALUE obj, obj2; @@ -462,6 +489,22 @@ true_and(obj, obj2) return RTEST(obj2)?Qtrue:Qfalse; } +/* + * call-seq: + * true | obj => true + * + * Or---Returns true. As anObject is an argument to + * a method call, it is always evaluated; there is no short-circuit + * evaluation in this case. + * + * true | puts("or") + * true || puts("logical or") + * + * produces: + * + * or + */ + static VALUE true_or(obj, obj2) VALUE obj, obj2; @@ -469,6 +512,16 @@ true_or(obj, obj2) return Qtrue; } + +/* + * call-seq: + * true ^ obj => !obj + * + * Exclusive Or---Returns true if obj is + * nil or false, false + * otherwise. + */ + static VALUE true_xor(obj, obj2) VALUE obj, obj2; @@ -566,6 +619,52 @@ rb_false(obj) return Qfalse; } + +/********************************************************************** + * Document-class: Symbol + * + * Symbol objects represent names and some strings + * inside the Ruby + * interpreter. They are generated using the :name and + * :"string" literals + * syntax, and by the various to_sym methods. The same + * Symbol object will be created for a given name or string + * for the duration of a program's execution, regardless of the context + * or meaning of that name. Thus if Fred is a constant in + * one context, a method in another, and a class in a third, the + * Symbol :Fred will be the same object in + * all three contexts. + * + * module One + * class Fred + * end + * $f1 = :Fred + * end + * module Two + * Fred = 1 + * $f2 = :Fred + * end + * def Fred() + * end + * $f3 = :Fred + * $f1.id #=> 2514190 + * $f2.id #=> 2514190 + * $f3.id #=> 2514190 + * + */ + +/* + * call-seq: + * sym.to_i => fixnum + * sym.to_int => fixnum + * + * Returns an integer that is unique for each symbol within a + * particular execution of a program. + * + * :fred.to_i #=> 9809 + * "fred".to_sym.to_i #=> 9809 + */ + static VALUE sym_to_i(sym) VALUE sym; @@ -575,6 +674,16 @@ sym_to_i(sym) return LONG2FIX(id); } + +/* + * call-seq: + * sym.inspect => string + * + * Returns the representation of sym as a symbol literal. + * + * :fred.inspect #=> ":fred" + */ + static VALUE sym_inspect(sym) VALUE sym; @@ -594,6 +703,18 @@ sym_inspect(sym) return str; } + +/* + * call-seq: + * sym.id2name => string + * sym.to_s => string + * + * Returns the name or string corresponding to sym. + * + * :fred.id2name #=> "fred" + */ + + static VALUE sym_to_s(sym) VALUE sym; @@ -601,6 +722,16 @@ sym_to_s(sym) return rb_str_new2(rb_id2name(SYM2ID(sym))); } + +/* + * call-seq: + * sym.to_sym => sym + * + * In general, to_sym returns the Symbol correspopnding + * to an object. As sym is already a symbol, self is returned + * in this case. + */ + static VALUE sym_to_sym(sym) VALUE sym; -- cgit v1.2.3