Ruby 类
我对Mechanize::Cookie行为不端有一个问题,我想尝试对其进行修补。 我的代码:Ruby 类,ruby,mechanize,monkeypatching,alias-method,alias-method-chain,Ruby,Mechanize,Monkeypatching,Alias Method,Alias Method Chain,我对Mechanize::Cookie行为不端有一个问题,我想尝试对其进行修补。 我的代码: 如果没有补丁,您将看到一个完整的cookie jar,其中一个是空的。如果给定block\u,原始解析方法似乎有一个成品cookie?其中的声明。你还需要通过一个街区 编辑: 更清楚地说 class Foo def self.x yield "yielded from x!" if block_given? end end class Foo class <
如果没有补丁,您将看到一个完整的cookie jar,其中一个是空的。如果给定block\u,原始解析方法似乎有一个成品cookie?其中的声明。你还需要通过一个街区 编辑: 更清楚地说
class Foo
def self.x
yield "yielded from x!" if block_given?
end
end
class Foo
class <<self
alias :y :x
end
# new implementation of x's last parameter is an optional block
def self.x(&block)
puts "in redefined x."
puts "block=#{block}"
self.y(&block) #use the block as the last parameter
end
end
Foo.x{|value| puts "value is '#{value}'"}
如果给定块,原始解析方法似乎有一个成品cookie?其中的声明。你还需要通过一个街区 编辑: 更清楚地说
class Foo
def self.x
yield "yielded from x!" if block_given?
end
end
class Foo
class <<self
alias :y :x
end
# new implementation of x's last parameter is an optional block
def self.x(&block)
puts "in redefined x."
puts "block=#{block}"
self.y(&block) #use the block as the last parameter
end
end
Foo.x{|value| puts "value is '#{value}'"}
做新的解析!打印出来?是的,新的解析!打印出来,我可以看出旧的_parse也被调用了,因为我在那里放了一行“puts”来检查它。但是当我包含此代码时,cookies不会被保存。当你不包含此代码时,cookies会被保存,对吗?@Andrew,没错。我已经编辑了我的问题以帮助显示问题。进行新的分析!打印出来?是的,新的解析!打印出来,我可以看出旧的_parse也被调用了,因为我在那里放了一行“puts”来检查它。但是当我包含此代码时,cookies不会被保存。当你不包含此代码时,cookies会被保存,对吗?@Andrew,没错。我编辑了我的问题以帮助说明问题。谢谢z5h,我认为这是正确的答案。如果你有提示的话,我可以用另一个提示。谢谢z5h,我认为这是正确的答案。如果你有一个提示的话,我可以用另一个提示。
class Foo
def self.x
yield "yielded from x!" if block_given?
end
end
class Foo
class <<self
alias :y :x
end
# new implementation of x's last parameter is an optional block
def self.x(&block)
puts "in redefined x."
puts "block=#{block}"
self.y(&block) #use the block as the last parameter
end
end
Foo.x{|value| puts "value is '#{value}'"}