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

ruby-changes:25321

From: marcandre <ko1@a...>
Date: Mon, 29 Oct 2012 06:19:59 +0900 (JST)
Subject: [ruby-changes:25321] marcandRe: r37374 (trunk): * lib/ostruct.rb: Simplify code

marcandre	2012-10-29 06:19:32 +0900 (Mon, 29 Oct 2012)

  New Revision: 37374

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

  Log:
    * lib/ostruct.rb: Simplify code

  Modified files:
    trunk/lib/ostruct.rb

Index: lib/ostruct.rb
===================================================================
--- lib/ostruct.rb	(revision 37373)
+++ lib/ostruct.rb	(revision 37374)
@@ -159,15 +159,13 @@
   #
   # Used internally to defined properties on the
   # OpenStruct. It does this by using the metaprogramming function
-  # define_method for both the getter method and the setter method.
+  # define_singleton_method for both the getter method and the setter method.
   #
   def new_ostruct_member(name)
     name = name.to_sym
-    unless self.respond_to?(name)
-      class << self; self; end.class_eval do
-        define_method(name) { @table[name] }
-        define_method("#{name}=") { |x| modifiable[name] = x }
-      end
+    unless respond_to?(name)
+      define_singleton_method(name) { @table[name] }
+      define_singleton_method("#{name}=") { |x| modifiable[name] = x }
     end
     name
   end

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

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