* 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:
parent
3098d80818
commit
3044252beb
@ -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>
|
Wed Feb 14 13:12:06 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* re.c (reg_operand): allow symbols to be operands for regular
|
* re.c (reg_operand): allow symbols to be operands for regular
|
||||||
|
@ -95,24 +95,23 @@ class Date
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Bag # :nodoc:
|
class Bag # :nodoc:
|
||||||
|
def initialize
|
||||||
|
@_dict = {}
|
||||||
|
end
|
||||||
|
|
||||||
def method_missing(t, *args, &block)
|
def method_missing(t, *args, &block)
|
||||||
t = t.to_s
|
if /=$/ =~ t
|
||||||
set = t.chomp!('=')
|
t = t.to_s.chomp('=').to_sym
|
||||||
t = '@v' + t
|
@_dict[t] = args[0]
|
||||||
if set
|
|
||||||
instance_variable_set(t, *args)
|
|
||||||
else
|
else
|
||||||
if instance_variables.include?(t)
|
if @_dict.key?(t)
|
||||||
instance_variable_get(t)
|
@_dict[t]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
instance_variables.
|
@_dict.reject{|k,v| /^_/ =~ k}
|
||||||
select{|n| !instance_variable_get(n).nil?}.grep(/\A@v[^_]/).
|
|
||||||
inject({}){|r, n| r[n[2..-1].intern] = instance_variable_get(n); r}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user