1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/date/format.rb (Date::Format::Bag::method_missing): need not

to use instance variables corresponding each method; use Hash
  instead.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-02-14 08:10:10 +00:00
parent 3098d80818
commit 3044252beb
2 changed files with 15 additions and 10 deletions

View file

@ -1,3 +1,9 @@
Wed Feb 14 16:48:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/date/format.rb (Date::Format::Bag::method_missing): need not
to use instance variables corresponding each method; use Hash
instead.
Wed Feb 14 13:12:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (reg_operand): allow symbols to be operands for regular

View file

@ -95,24 +95,23 @@ class Date
end
class Bag # :nodoc:
def initialize
@_dict = {}
end
def method_missing(t, *args, &block)
t = t.to_s
set = t.chomp!('=')
t = '@v' + t
if set
instance_variable_set(t, *args)
if /=$/ =~ t
t = t.to_s.chomp('=').to_sym
@_dict[t] = args[0]
else
if instance_variables.include?(t)
instance_variable_get(t)
if @_dict.key?(t)
@_dict[t]
end
end
end
def to_hash
instance_variables.
select{|n| !instance_variable_get(n).nil?}.grep(/\A@v[^_]/).
inject({}){|r, n| r[n[2..-1].intern] = instance_variable_get(n); r}
@_dict.reject{|k,v| /^_/ =~ k}
end
end