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
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/stupidedi/versions/functional_groups/004010/element_types/operators.rb', line 71
def relational_operators(*ops)
file, line, = Stupidedi.caller
if ops.last.is_a?(Hash)
options = ops.pop
case options[:coerce]
when String, Symbol
coerce = options[:coerce]
else
raise ArgumentError,
"must pass :coerce => :method"
end
else
raise ArgumentError,
"must pass :coerce => :method"
end
ops.each do |op|
class_eval(<<-RUBY, file, line.to_i - 1)
def #{op}(other, &block)
begin
value.#{op}(other.#{coerce}, &block)
rescue NoMethodError
begin
me, he = other.coerce(self)
me.#{op}(he, &block)
rescue NoMethodError
raise TypeError,
"cannot coerce \#{other.class} to \#{self.class}"
end
end
end
RUBY
end
end
|