G
Greg Willits
Can I depend on .methods returning methods in the order they are written
in the class source code?
I would assume Unit::Test counts on that, and playing around with this
test seems to indicate that order is retained, but not sure if I'm just
getting lucky. (Seems weird that order is retained, yet the names are
dispersed among all the other inherited methods of the class, rather
than grouped at the end or something.)
class Matchers
def match_first
end
def match_second
end
def match_another
end
def match_last_one
end
end
x = Matchers.new
matchers = []
x.methods.each do |method_name|
matchers << method_name if method_name.scan(/^match_/)[0]
end
p matchers
# => ["match_first", "match_second", "match_another", "match_last_one"]
Thx
-- gw
in the class source code?
I would assume Unit::Test counts on that, and playing around with this
test seems to indicate that order is retained, but not sure if I'm just
getting lucky. (Seems weird that order is retained, yet the names are
dispersed among all the other inherited methods of the class, rather
than grouped at the end or something.)
class Matchers
def match_first
end
def match_second
end
def match_another
end
def match_last_one
end
end
x = Matchers.new
matchers = []
x.methods.each do |method_name|
matchers << method_name if method_name.scan(/^match_/)[0]
end
p matchers
# => ["match_first", "match_second", "match_another", "match_last_one"]
Thx
-- gw