This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
/
Trac911.rb
101 lines (92 loc) · 2.13 KB
/
Trac911.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Extracted from rubygems 1.8.5 deprecate.rb
#
# Expected behavior:
#
# $ ruby $pbm
# 10
# WARN: foo deprecated
# 10
#
# MagLev behavior
#
# $ mruby $pbm
# 10
# error , a ArgumentError occurred (error 2718), too few args,
# during /Users/pmclain/tmp/pbm.rb
# ERROR 2718 , a ArgumentError occurred (error 2718), too few args (ArgumentError)
#
class F
def self.deprecate(name)
class_eval {
old = "_deprecated_#{name}"
alias_method old, name
# In the rubygems source, there is the following comment next to this
# define_method:
# # TODO: really works on 1.8.7?
define_method name do |*args, &block|
puts "WARN: #{name} deprecated"
send old, *args, &block
end
}
end
def foo
10
end
end
p F.new.foo # before deprecation, foo() runs fine
class F; deprecate(:foo); end
p F.new.foo # Problem after deprecation
#################### Trac Info
# ID: 911
# Summary: Problem with RubyGems 1.8.5: argument error with alias and define_method
# Changetime: 2011-06-06 23:24:49+00:00
###
# {{{
# # Extracted from rubygems 1.8.5 deprecate.rb
# #
# # Expected behavior:
# #
# # $ ruby $pbm
# # 10
# # WARN: foo deprecated
# # 10
# #
# # MagLev behavior
# #
# # $ mruby $pbm
# # 10
# # error , a ArgumentError occurred (error 2718), too few args,
# # during /Users/pmclain/tmp/pbm.rb
# # ERROR 2718 , a ArgumentError occurred (error 2718), too few args (ArgumentError)
# #
#
# class F
# def self.deprecate(name)
# class_eval {
#
# old = "_deprecated_#{name}"
# alias_method old, name
#
# # In the rubygems source, there is the following comment next to this
# # define_method:
# # # TODO: really works on 1.8.7?
# define_method name do |*args, &block|
# puts "WARN: #{name} deprecated"
# send old, *args, &block
# end
#
# }
# end
#
# def foo
# 10
# end
# end
#
# p F.new.foo # before deprecation, foo() runs fine
#
# class F; deprecate(:foo); end
#
# p F.new.foo # Problem after deprecation
# }}}
#