mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/date/format.rb (Date::Format::Bag): use Struct.
as an experimental. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
45bfb5318f
commit
2f8ddcd8cd
2 changed files with 21 additions and 18 deletions
|
@ -1,3 +1,8 @@
|
|||
Tue Aug 10 20:56:13 2010 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* lib/date/format.rb (Date::Format::Bag): use Struct.
|
||||
as an experimental.
|
||||
|
||||
Tue Aug 10 20:45:35 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/pathname/pathname.c (path_rename): Pathname#rename translated
|
||||
|
|
|
@ -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 @@ class Date
|
|||
x.freeze
|
||||
end
|
||||
|
||||
class Bag # :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]
|
||||
end
|
||||
end
|
||||
class BagStruct < Struct # :nodoc:
|
||||
|
||||
def to_hash
|
||||
@elem.reject{|k, v| /\A_/ =~ k.to_s || v.nil?}
|
||||
h = {}
|
||||
members.each do |k|
|
||||
unless /\A_/ =~ k.to_s || self[k].nil?
|
||||
h[k] = self[k]
|
||||
end
|
||||
end
|
||||
h
|
||||
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:
|
||||
|
|
Loading…
Add table
Reference in a new issue