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

ruby-changes:16957

From: tadf <ko1@a...>
Date: Tue, 10 Aug 2010 21:00:06 +0900 (JST)
Subject: [ruby-changes:16957] Ruby:r28953 (trunk): * lib/date/format.rb (Date::Format::Bag): use Struct.

tadf	2010-08-10 20:58:21 +0900 (Tue, 10 Aug 2010)

  New Revision: 28953

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

  Log:
    * lib/date/format.rb (Date::Format::Bag): use Struct.
      as an experimental.

  Modified files:
    trunk/ChangeLog
    trunk/lib/date/format.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28952)
+++ ChangeLog	(revision 28953)
@@ -1,3 +1,8 @@
+Tue Aug 10 20:56:13 2010  Tadayoshi Funaba  <tadf@d...>
+
+	* lib/date/format.rb (Date::Format::Bag): use Struct.
+	  as an experimental.
+
 Tue Aug 10 20:45:35 2010  Tanaka Akira  <akr@f...>
 
 	* ext/pathname/pathname.c (path_rename): Pathname#rename translated
Index: lib/date/format.rb
===================================================================
--- lib/date/format.rb	(revision 28952)
+++ lib/date/format.rb	(revision 28953)
@@ -1,4 +1,4 @@
-# format.rb: Written by Tadayoshi Funaba 1999-2009
+# format.rb: Written by Tadayoshi Funaba 1999-2010
 # $Id: format.rb,v 2.43 2008-01-17 20:16:31+09 tadf Exp $
 
 class Date
@@ -109,29 +109,27 @@
       x.freeze
     end
 
-    class Bag # :nodoc:
+    class BagStruct < Struct # :nodoc:
 
-      def initialize
-	@elem = {}
-      end
-
-      def method_missing(t, *args, &block)
-	t = t.to_s
-	set = t.chomp!('=')
-	t = t.intern
-	if set
-	  @elem[t] = args[0]
-	else
-	  @elem[t]
+      def to_hash
+	h = {}
+	members.each do |k|
+	  unless /\A_/ =~ k.to_s || self[k].nil?
+	    h[k] = self[k]
+	  end
 	end
+	h
       end
 
-      def to_hash
-	@elem.reject{|k, v| /\A_/ =~ k.to_s || v.nil?}
-      end
-
     end
 
+    Bag = BagStruct.new(:year, :mon, :yday, :mday, :wday,
+			:cwyear, :cweek, :cwday,
+			:hour, :min, :sec, :sec_fraction,
+			:wnum0, :wnum1, :seconds,
+			:zone, :offset, :leftover,
+			:_cent, :_merid, :_comp)
+
   end
 
   def emit(e, f) # :nodoc:

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

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