[前][次][番号順一覧][スレッド一覧]

ruby-changes:28630

From: nobu <ko1@a...>
Date: Mon, 13 May 2013 14:53:04 +0900 (JST)
Subject: [ruby-changes:28630] nobu:r40682 (trunk): class.c: rb_singleton_class_get

nobu	2013-05-13 14:50:38 +0900 (Mon, 13 May 2013)

  New Revision: 40682

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40682

  Log:
    class.c: rb_singleton_class_get
    
    * class.c (rb_singleton_class_get): get the singleton class if exists,
      or nil.

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/internal.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40681)
+++ ChangeLog	(revision 40682)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May 13 14:50:35 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* class.c (rb_singleton_class_get): get the singleton class if exists,
+	  or nil.
+
 Mon May 13 10:20:59 2013  Yuki Yugui Sonoda  <yugui@g...>
 
 	* ext/openssl/ossl_ssl.c: Disabled OpenSSL::SSL::SSLSocket if
Index: class.c
===================================================================
--- class.c	(revision 40681)
+++ class.c	(revision 40682)
@@ -1448,6 +1448,26 @@ singleton_class_of(VALUE obj) https://github.com/ruby/ruby/blob/trunk/class.c#L1448
     return klass;
 }
 
+/*!
+ * Returns the singleton class of \a obj, or nil if obj is not a
+ * singleton object.
+ *
+ * \param obj an arbitrary object.
+ * \return the singleton class or nil.
+ */
+VALUE
+rb_singleton_class_get(VALUE obj)
+{
+    VALUE klass;
+
+    if (SPECIAL_CONST_P(obj)) {
+	return rb_special_singleton_class(obj);
+    }
+    klass = RBASIC(obj)->klass;
+    if (!FL_TEST(klass, FL_SINGLETON)) return Qnil;
+    if (rb_ivar_get(klass, id_attached) != obj) return Qnil;
+    return klass;
+}
 
 /*!
  * Returns the singleton class of \a obj. Creates it if necessary.
Index: internal.h
===================================================================
--- internal.h	(revision 40681)
+++ internal.h	(revision 40682)
@@ -96,6 +96,7 @@ VALUE rb_obj_public_methods(int argc, VA https://github.com/ruby/ruby/blob/trunk/internal.h#L96
 int rb_obj_basic_to_s_p(VALUE);
 VALUE rb_special_singleton_class(VALUE);
 VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach);
+VALUE rb_singleton_class_get(VALUE obj);
 void Init_class_hierarchy(void);
 
 /* compar.c */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]